UIlabel设置不同的颜色

NSString *string = @"注册过程中出现问题,致电400-650-5167联系会养车工作人员";
    NSRange range = [string rangeOfString: @"400-650-5167"];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString: string];
    [attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor colorWithRed:84.0f/255.0f green:116.0f/255.0f blue:173.0f/255.0f alpha:1.0f]} range: range];
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0, 200, 320.0, 100.0)];
    [label setText: string];
    label.textColor = [UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1.0f];
    label.font = [UIFont boldSystemFontOfSize:14];
    label.numberOfLines = 0;
    [label setAttributedText: attribute];
    [self.view addSubview:label]; 

原文地址:https://www.cnblogs.com/wskgjmhh/p/4764883.html