美文网首页
iOS UILabel设置文字的不同样式

iOS UILabel设置文字的不同样式

作者: _桃夭大人_ | 来源:发表于2016-07-13 10:02 被阅读100次

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设置文字的不同样式

      本文链接:https://www.haomeiwen.com/subject/jnmsjttx.html