首页 > 代码库 > UILabel Attributed 富文本

UILabel Attributed 富文本

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Menlo; color: #703daa } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px "PingFang SC"; color: #008400 } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Menlo; color: #008400 } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Menlo; color: #3e1e81 } span.s1 { color: #703daa } span.s2 { } span.s3 { color: #3e1e81 } span.s4 { color: #d12f1b } span.s5 { font: 16.0px "PingFang SC"; color: #d12f1b } span.s6 { color: #008400 } span.s7 { font: 16.0px "PingFang SC"; color: #008400 } span.s8 { color: #000000 } span.s9 { font: 16.0px Menlo; color: #000000 } span.s10 { font: 16.0px Menlo } span.s11 { color: #272ad8 } span.s12 { font: 16.0px "PingFang SC" }</style>

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 富文本