iOS label的文字显示不同的颜色


    UILabel * goodtotalLabel = [UILabel new];
    goodtotalLabel.textColor = ZDColor_Red;
    //原来label文字的颜色
    NSMutableAttributedString *hintString =[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"总计:¥ %.2f  ",sum]];
    //获取要调整颜色的文字位置
    NSRange range =[[hintString string]rangeOfString:@"总计:¥"];
    [hintString addAttribute:NSForegroundColorAttributeName value:ZDColor_Black range:range];
    goodtotalLabel.attributedText = hintString;

你可能感兴趣的:(iOS label的文字显示不同的颜色)