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: 有疑问欢迎留言。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容