iOS开发之修改NSString字符串中某段字符串的颜色

一. 修改NSString字符串中某段字符串的颜色

NSMutableAttributedString *totalContentAttributedStr = [[NSMutableAttributedString alloc] initWithString: resultStr];    
UIColor *highLightColor = COLOR_RED;   
[totalContentAttributedStr setAttributes:@{NSForegroundColorAttributeName : highLightColor, NSFontAttributeName : [AdaptiveClass ultimateEditionBySize:17 isBlod:NO]} range:NSMakeRange(firstItemStr.length, keyStr.length)];
self.contentLabel.attributedText = totalContentAttributedStr;
NSAttributedString,NSMutableAttributedString是带属性的特殊字符串,NSMutableParagraphStyle是带属性的文本段落属性,用于控制段落有关属性

**1、NSAttributedString **

参考

  • http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c422461b1132a0f824281a0ed0c17f6c03b21a1cacab672c601e76e0dd9bd3149ca69528288b2630701d92044f934fa0901b64d621e04d99db0e94c9e74296b9a1d3c854229612127bf0afcc4d01648c3ca04a66f4a7e90a461f43efad6327a54e7659de650be810eee043797180e1ac5d5bb32fc7121b&p=857e8e15d9c041af34be9b7c4c49cc&newp=9e6ac216d9c118ff57ee947e4f00a5231610db2151d7d2116b82c825d7331b001c3bbfb423231404d1c77c6405a94257e8f23c73350621a3dda5c91d9fb4c57479d1&user=baidu&fm=sc&query=iOS%BF%AA%B7%A2++NSMutableParagraphStyle+%D3%C3%B7%A8&qid=8586c0c80002e700&p1=3

你可能感兴趣的:(iOS开发之修改NSString字符串中某段字符串的颜色)