转载注明出处:http://blog.youkuaiyun.com/hzhenx1989/article/details/30307187
今天在处理一个UI问题,需要现在一段字体,然后对该段字体的某部分进行高亮显示,如下
这个一个Label标签
NSAttributedString的使用请自己查阅一下官方文档,这里我使用了下面的一个方法,
- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range;
如果设置了Text,那么所有效果会失效,所以只能通过attributedString去替代text
官方提供了name有
/************************ Attributes ************************/
/* Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below.
*/
UIKIT_EXTERN NSString *const NSFontAttributeNameNS_AVAILABLE_IOS(6_0); // UIFont, defa