Label中同一段字体中实现不同的字体颜色、删除线,下划线标题文章

// 创建NSMutableAttributedString 字符串
NSMutableAttributedString *attriString =[[NSMutableAttributedString alloc] initWithString:@"This istest"];

 

//把this的字体颜色变成红色

[attriString addAttribute:(NSString*)NSForegroundColorAttributeName value:[UIColor greenColor]range:NSMakeRange(0, 4)];

[attriStringaddAttribute:(NSString *)NSForegroundColorAttributeNamevalue:(id)[UIColor redColor] range:NSMakeRange(5, 2)];


//给this添加删除线,value可以指定的枚举中选择

[attriString addAttribute:(NSString*)NSStrikethroughStyleAttributeName value:(id)[NSNumbernumberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0,4)];

//给this添加双下划线,

[attriStringaddAttribute:(NSString *)NSUnderlineStyleAttributeNamevalue:(id)[NSNumber numberWithInt:NSUnderlineStyleDouble]range:NSMakeRange(0, 4)];

UILabel*label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 100,60)];

[self.viewaddSubview:label];

label.attributedText = attriString;


PS: 有疑问欢迎留言。

你可能感兴趣的:(Label中同一段字体中实现不同的字体颜色、删除线,下划线标题文章)