首页 > 其他 > 详细

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

时间:2014-03-26 10:09:36      阅读:263      评论:0      收藏:0      [点我收藏+]

    //带有属性的文字

    //1.创建对象

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

  NSMutableAttributedString *attrTitle = [[NSMutableAttributedStringalloc] initWithString: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 alloc] init];

    label.frame = CGRectMake(100, 100, 100, 40);

    [label setAttributedText:attrTitle];

    [self.view addSubview:label];

带属性的字符串(NSMutableAttributedString)的使用,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/d2688/p/3622344.html

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