IOS开发-UI学习-NSMutableAttributedString(带属性的字符串)的使用

带属性的字符串:

 

 1 NSString *aa = @"hellochinaIloveYou!";
 2     NSMutableAttributedString *mas = [[NSMutableAttributedString alloc]initWithString:aa];
 3     
 4 //    设置字符串字属性
 5     UIFont *font = [UIFont fontWithName:@"Arial" size:35.0f];
 6     [mas addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, 17)];
 7 //    设置字体颜色
 8     [mas addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 15)];
 9 //    设置背景色
10     [mas addAttribute:NSBackgroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 13)];
11 //    设置字符间距
12     [mas addAttribute:NSKernAttributeName value:[NSNumber numberWithFloat:10.1] range:NSMakeRange(0, 9)];
13 //    设置删除线线型
14     [mas addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(0, 19)];
15 //    设置删除线颜色
16     [mas addAttribute:NSStrikethroughColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 7)];
17 //    设置字体倾斜
18     [mas addAttribute:NSObliquenessAttributeName value:[NSNumber numberWithFloat:0.6] range:NSMakeRange(0, 5)];
19 //    拉伸字体
20     [mas addAttribute:NSExpansionAttributeName value:[NSNumber numberWithFloat:0.9] range:NSMakeRange(0, 3)];
21 //    设置下划线
22     [mas addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, 7)];
23 //    设置下划线颜色
24     [mas addAttribute:NSUnderlineColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, 7)];
25 //    设置搂空字体
26     [mas addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithInt:12] range:NSMakeRange(0, 9)];
27 //    搂空字体设置颜色
28     [mas addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 9)];
29 //    设置阴影
30     NSShadow *shadow = [[NSShadow alloc]init];
31     shadow.shadowBlurRadius = 10;
32     shadow.shadowColor = [UIColor colorWithRed:0.502 green:0.023 blue:0.134 alpha:1.000];
33     shadow.shadowOffset = CGSizeMake(-0.1, 0.1);
34     [mas addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, 19)];
35 //    设置印刷字体
36     [mas addAttribute:NSTextEffectAttributeName value:NSTextEffectLetterpressStyle range:NSMakeRange(0, 6)];
37     
38     
39     
40     
41     
42     
43     UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 200, 418, 100)];
44 //    label.text = mas.string;
45     label.attributedText =mas;
46     
47     [self.view addSubview:label];

 

posted @ 2016-04-07 15:50  jiwangbujiu  阅读(469)  评论(0编辑  收藏  举报