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;

posted @ 2017-07-02 19:43  justqi  阅读(158)  评论(0编辑  收藏  举报