NSAttributedString 多格式字符串

NSString *aString = @"哈哈标题(必填)";
NSRange range = NSMakeRange(4, 4);
//当然也可以查找NSRange range = [aString rangeOfString:@"(必填)"];
NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:aString];
[tempString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:range];

除了

NSForegroundColorAttributeName 颜色,还有其他属性

NSFontAttributeName 字体UIFont

NSParagraphStyleAttributeName 段落风格等...

其他的自己可以去找找看看

转载于:https://www.cnblogs.com/YaphetsDiao/p/6088031.html

你可能感兴趣的:(NSAttributedString 多格式字符串)