天天看點

NSMutableAttributedString(帶屬性的string)

 mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 50, 1000, 50)];

    mylabel.backgroundColor=[UIColor brownColor];

    [self.view addSubview:mylabel];

    NSString *string=@"welcome to china";

    NSMutableAttributedString *attrstring=[[NSMutableAttributedString alloc]initWithString:string];

    //字型大小

    [attrstring addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"DIN Condensed" size:26] range:NSMakeRange(0, 4)];

    //字型顔色

    [attrstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];

//    //背景色

//    [attrstring addAttribute:NSBackgroundColorAttributeName value:[UIColor purpleColor] range:NSMakeRange(0, 4)];

//    //間距

//    [attrstring addAttribute:NSKernAttributeName value:[NSNumber numberWithFloat:12.0] range:NSMakeRange(0, string.length)];

//    //删除線

//    [attrstring addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(0,string.length)];

//    [attrstring addAttribute:NSStrikethroughColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.length)];

//    //傾斜度

//    [attrstring addAttribute:NSObliquenessAttributeName value:[NSNumber numberWithFloat:1.3] range:NSMakeRange(0, string.length-3)];

//    //拉伸

//    [attrstring addAttribute:NSExpansionAttributeName value:[NSNumber numberWithFloat:1.3] range:NSMakeRange(0, string.length-3)];

//    //下劃線

    [attrstring addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(0, string.length-3)];

    [attrstring addAttribute:NSUnderlineColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, string.length-3)];

//    //畫筆的顔色和寬度

//    [attrstring addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithInteger:2] range:NSMakeRange(0, string.length)];

//    [attrstring addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, string.length-3)];

//    //陰影

//    NSShadow *show=[[NSShadow alloc]init];

//    show.shadowBlurRadius=1.0;

//    show.shadowColor=[UIColor redColor];

//    show.shadowOffset=CGSizeMake(10, 1);

//    [attrstring addAttribute:NSShadowAttributeName value:show range:NSMakeRange(0, 1)];

    //印刷體

    [attrstring addAttribute:NSTextEffectAttributeName value:NSTextEffectLetterpressStyle range:NSMakeRange(4, 10)];

    mylabel.attributedText=attrstring;

}