zoukankan      html  css  js  c++  java
  • NSMutableAttributedString(改变文字颜色)

    //类型
    //创建一个label   
    UILabel *label1=[[UILabel alloc]initWithFrame:CGRectMake(130, 60,250, 150)];
        [self.window addSubview:label1];
        label1.text=@"评分:7.1   (4925评论) 20140901        date 126min         runtime 动作/冒险/惊悚        genres 美国|法国        country";
        label1.numberOfLines=0;
    //类型字体颜色
    //创建NSMutableAttributedString   
    NSMutableAttributedString *mstring=[[[NSMutableAttributedString alloc]initWithString:@"评分:7.1   (4925评论) 20140901        date 126min         runtime 动作/冒险/惊悚        genres 美国|法国        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;
  • 相关阅读:
    socket错误码获取
    代码整洁之道读书笔记函数
    算法学习之堆排序
    包含与继承区别
    提高 LayerBacked Memory Use
    RenderBuffer
    算法学习之快速排序
    NSTimer
    DNS and BIND ... (转载) zhumao
    Samba学习笔记(转载) zhumao
  • 原文地址:https://www.cnblogs.com/lsh1234/p/4902710.html
Copyright © 2011-2022 走看看