美文网首页iOS Developer
Label中同一段字体中实现不同的字体颜色、删除线,下划线标题文

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

作者: 走在路上的小二 | 来源:发表于2016-11-24 10:22 被阅读141次

// 创建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中同一段字体中实现不同的字体颜色、删除线,下划线标题文

    本文链接:https://www.haomeiwen.com/subject/hgdbpttx.html