NSMutableAttributedString富文本使用
2018-07-17 本文已影响0人
哈利波特会魔法
UILabel *label = [[UILabel alloc] init];
NSString *wordStr = @"i-Do-Not-Like-The-Word-I-Only-Like-You";
label.text = wordStr;
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:wordStr];
NSRange range = [wordStr rangeOfString:@"I"];
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(range.location, wordStr.length - range.location)];
label.attributedText = attStr;