码迷,mamicode.com
首页 > 移动开发 > 详细

IOS-同一label显示不同字体颜色

时间:2015-07-23 15:37:35      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:ios   uilabel   uicolor   

UILabel* noteLabel = [[UILabel alloc] init];
noteLabel.frame = CGRectMake(0, 100, 200, 100);
noteLabel.textColor = [UIColor blackColor];
NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@”1111:2222”];
NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@”:”].location);
[noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
[noteLabel setAttributedText:noteStr] ;
[noteLabel sizeToFit];
[self.view addSubview:noteLabel];

版权声明:本文为博主原创文章,未经博主允许不得转载。

IOS-同一label显示不同字体颜色

标签:ios   uilabel   uicolor   

原文地址:http://blog.csdn.net/u010742414/article/details/47022647

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!