IOS系统原生富文本

UILabel* lbl = [[UILabel alloc] init];
NSString* str = [NSString stringWithFormat:@"%@ %@", repeat, item.remember];
NSMutableAttributedString* aStr = [[NSMutableAttributedString alloc] initWithString:str];

[aStr addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                    [UIFont systemFontOfSize:14],
                    NSFontAttributeName,
                    [UIColor blackColor],
                    NSForegroundColorAttributeName,
                    nil]
              range:[str rangeOfString:repeat]];
        
[aStr addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                    [UIFont systemFontOfSize:14],
                    NSFontAttributeName,
                    RGBCOLOR(188, 188, 188),
                    NSForegroundColorAttributeName,
                    nil]
              range:[str rangeOfString:item.remember]];
        
lbl.attributedText = aStr;

你可能感兴趣的:(IOS开发)