| 
TA的每日心情|  | 汗 2024-10-15 10:05
 | 
|---|
 签到天数: 372 天 [LV.9]以坛为家II | 
 
| 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
 | 
 |