首页 > 其他 > 详细

NSMutableAttributedString(改变文字颜色)

时间:2015-10-22 21:27:14      阅读:272      评论:0      收藏:0      [点我收藏+]
//类型
//创建一个label   
UILabel *label1=[[UILabel alloc]initWithFrame:CGRectMake(130, 60,250, 150)];
    [self.window addSubview:label1];
    label1.text=@"评分:7.1   (4925评论)\n20140901        date\n126min         runtime\n动作/冒险/惊悚        genres\n美国|法国        country";
    label1.numberOfLines=0;
//类型字体颜色
//创建NSMutableAttributedString   
NSMutableAttributedString *mstring=[[[NSMutableAttributedString alloc]initWithString:@"评分:7.1   (4925评论)\n20140901        date\n126min         runtime\n动作/冒险/惊悚        genres\n美国|法国        country "] autorelease];
//定义  
[mstring addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]  range:NSMakeRange(34, 4)];
    [mstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]  range:NSMakeRange(54, 7)];
    [mstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]  range:NSMakeRange(78, 6)];
   
    [mstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]  range:NSMakeRange(99, 7)];
   //将 NSMutableAttributedString赋给UIlabel
    label1.attributedText=mstring;

NSMutableAttributedString(改变文字颜色)

原文:http://www.cnblogs.com/lsh1234/p/4902710.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!