iOS UILabel设置文字的不同样式

NSString * contentStr= @" 75%\n7500\n10000";

NSRange rang = [contentStr rangeOfString:@"%"];

NSMutableAttributedString *textStr = [[NSMutableAttributedString alloc] initWithString:contentStr];

//        UIColor * color = [[UIColor alloc]initWithRed:228/255.0 green:190/255.0 blue:52/255.0 alpha:1];

[textStr addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0,rang.location +1)];

[textStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:fontWidth+5] range:NSMakeRange(0,rang.location +1)];

[textStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:fontWidth-6] range:NSMakeRange(rang.location + 1,contentStr.length - rang.location -1 )];

[textStr addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(rang.location + 1,contentStr.length - rang.location -1 )];

label.attributedText = textStr;

你可能感兴趣的:(iOS UILabel设置文字的不同样式)