年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2328|回复: 0

富文本(NSMutableAttributedString)的使用

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2014-7-14 09:36:53 | 显示全部楼层 |阅读模式
    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];

    参考链接:http://www.cnblogs.com/d2688/p/3622344.html
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-5-1 19:15 , Processed in 0.043091 second(s), 19 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表