一段文字多种颜色

    UILabel *introduceLb = [UILabel new];
    introduceLb.text = @"如果您需要更全面和专业的检测,建议您到健康商城购买心电专业读图服务包,购买后监测24小时心电信息并通过底座上传,得到专业医生的评估报告";
    NSMutableAttributedString *atrributeStr=[[NSMutableAttributedString alloc] initWithString:self.introduceLb.text ];
    //设置字体颜色
    [atrributeStr addAttribute:NSForegroundColorAttributeName
                          value:[UIColor colorWithHexString:@"33B7F5"]
                          range:NSMakeRange(19, 4)];
    [atrributeStr addAttribute:NSForegroundColorAttributeName
                          value:[UIColor colorWithHexString:@"33B7F5"]
                          range:NSMakeRange(25, 9)];
    introduceLb.attributedText=atrributeStr;

效果如下:

猜你喜欢

转载自blog.csdn.net/lee727n/article/details/90765031