iOS在label中显示不同颜色的字
2017-03-29 17:53
417 查看
UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 30)];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"set
background color with button"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,2)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0] range:NSMakeRange(0, 5)];
[string addAttribute:NSFontAttributeName value:[UIFontfontWithName:@"HelveticaNeue-Bold" size:17.0] range:NSMakeRange(6, 12)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:17.0] range:NSMakeRange(19, 6)];
Label.attributedText = string;
[self.view addSubview:Label];
效果图 : set background
color with button
原文地址:http://blog.csdn.net/sevenquan/article/details/50435373
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"set
background color with button"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,2)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0] range:NSMakeRange(0, 5)];
[string addAttribute:NSFontAttributeName value:[UIFontfontWithName:@"HelveticaNeue-Bold" size:17.0] range:NSMakeRange(6, 12)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:17.0] range:NSMakeRange(19, 6)];
Label.attributedText = string;
[self.view addSubview:Label];
效果图 : set background
color with button
原文地址:http://blog.csdn.net/sevenquan/article/details/50435373
相关文章推荐
- iOS 关于label上显示不同颜色的字体
- iOS Label显示不同颜色和字体
- iOS开发 label上显示不同颜色不同大小的字
- iOS在一个label中显示不同颜色的字体
- iOS 一个label中显示不同颜色的文字
- iOS label显示不同颜色的字体
- iOS开发~设置label上文字显示不同大小、颜色、字体类型
- iOS 开发~设置label上文字显示不同大小、颜色、字体类型
- iOS中Label实现显示不同颜色与字体的方法
- ios Label显示不同颜色文字
- iOS label的文字显示不同的颜色
- ios Label上显示不同颜色文字
- iOS 一个label中显示不同颜色的文字
- iOS在一个label中显示不同颜色的字体
- IOS-同一label显示不同字体颜色
- iOS 在UILabel显示不同的字体和颜色 NSMutableAttributedString
- iOS开发笔记--UILabel显示不同的字体和颜色
- iOS 在UILabel显示不同的字体和颜色
- Qt中在label中显示不同颜色的字符
- iOS 在UILabel显示不同的字体和颜色(转)