判断Range 使字符串 本别显示不同颜色

来源:互联网 发布:网络培训班 编辑:程序博客网 时间:2024/06/07 22:08

UILabel *coutentLabel = [[UILabelalloc] initWithFrame:CGRectMake(view.frame.size.width / 2, 0, view.frame.size.width /2 - 10, view.frame.size.height)];

    

    coutentLabel.font = [UIFontsystemFontOfSize:18];

    

    coutentLabel.text = str;

    

    coutentLabel.textAlignment =2;

    

    NSMutableAttributedString *strs = [[NSMutableAttributedStringalloc]initWithString:str];

    

   //设置:在0-3个单位长度内的内容显示成红色

    [strs addAttribute:NSForegroundColorAttributeNamevalue:CloudFitGreenrange:colorRange];

    

    coutentLabel.attributedText = strs;


0 0
原创粉丝点击