ios NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)

来源:互联网 发布:淘宝零食店铺知乎 编辑:程序博客网 时间:2024/05/21 19:21

效果图:


- (void)setLabText:(NSString *)text{    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:text];        [attributedStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:COLOR_252525} range:NSMakeRange(0, 4)];        [attributedStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:COLOR_0093FF} range:NSMakeRange(4, text.length-5)];       [attributedStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:COLOR_999999} range:NSMakeRange(text.length-2, 2)];        _Lab.attributedText = attributedStr;}


0 0
原创粉丝点击