美文网首页iOS进阶之路
一个lable显示不同的字体颜色

一个lable显示不同的字体颜色

作者: 郑军红 | 来源:发表于2016-12-08 10:55 被阅读10次

    #pragma mark ---- 固定字体颜色大小处理

    - (NSMutableAttributedString *)attrStrFrom:(NSString *)titleStr numberStr:(NSString *)numberStr

    {

    NSMutableAttributedString *arrString = [[NSMutableAttributedString alloc]initWithString:titleStr];

    // 设置前面几个字串的格式:蓝色 16.0f字号

    [arrString addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0f],

    NSForegroundColorAttributeName:[UIColor redColor]

    }

    range:[titleStr rangeOfString:numberStr]];

    return arrString;

    }

    使用:

    [lable setAttributedText:[self attrStrFrom:[NSString stringWithFormat:@"预计%@后发货",timeString] numberStr:timeString]];

    相关文章

      网友评论

      本文标题:一个lable显示不同的字体颜色

      本文链接:https://www.haomeiwen.com/subject/bsrgpttx.html