UILabel Attributed 富文本

Posted justqi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UILabel Attributed 富文本相关的知识,希望对你有一定的参考价值。

UILabel *lable = [[UILabel alloc] init];

    NSString *str = @"认证地区 未认证";//未认证-红色,下划线

    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str];

    //添加字体和设置字体的范围

    [attrStr addAttribute:NSFontAttributeName

                    value:[UIFont systemFontOfSize:30.0f]

                    range:NSMakeRange(0, 4)];

    //添加文字颜色

    [attrStr addAttribute:NSForegroundColorAttributeName

                    value:[UIColor redColor]

                    range:NSMakeRange(5,3)];

    //添加下划线

    [attrStr addAttribute:NSUnderlineStyleAttributeName

                    value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]

                    range:NSMakeRange(5, 3)];

    lable.attributedText = attrStr;

以上是关于UILabel Attributed 富文本的主要内容,如果未能解决你的问题,请参考以下文章