NSMutableAttributedString

来源:互联网 发布:最准确的生男生女算法 编辑:程序博客网 时间:2024/03/28 23:58

带属性的字符串(NSMutableAttributedString)的使用

    //带有属性的文字

    //1.创建对象

  NSString *original = @"今天你还好吗?";

  NSMutableAttributedString *attrTitle = [[NSMutableAttributedStringallocinitWithString:original];

  //2.设置颜色(NSForegroundColorAttributeName代表要设置颜色, value代表值, range 代表范围)

  /**

    其他设置:

      1.NSForegroundColorAttributeName //颜色

      2.NSFontAttributeName //字体

      3.NSBackgroundColorAttributeName //背景色

     //还有其他的很多的属性,可以自己去看苹果的API,这里不再详述

  */

  [attrTitle addAttribute:NSForegroundColorAttributeName value:[UIColorblueColor] range:NSMakeRange(0, 2)];

 //3.添加到Label中

    UILabel *label = [[UILabel allocinit];

    label.frame = CGRectMake(10010010040);

    [label setAttributedText:attrTitle];

    [self.view addSubview:label];


资源来自于:http://www.cnblogs.com/d2688/p/3622344.html
0 0
原创粉丝点击