iOS_Label 中显示不同的颜色和字体

    NSString *usedStr = [NSString stringWithFormat:@"满%@元可用",[couponData objectForKey:@"minimum_payment_amount"]];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:usedStr];
    // 设置字体颜色
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,1)];
    [str addAttribute:NSForegroundColorAttributeName value:HEXCOLOR(0x19898e) range:NSMakeRange(1,3)];
    [str addAttribute:NSForegroundColorAttributeName value:HEXCOLOR(0x26bbc8) range:NSMakeRange(4, 3)];
    // 设置字体
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0,1)];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(1,3)];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(4,3)];
    self.couponUsedLbl.attributedText = str;
Paste_Image.png

你可能感兴趣的:(iOS_Label 中显示不同的颜色和字体)