您的位置:首页 > 其它

Label中某几个字符颜色大小不同

2017-02-20 14:34 267 查看
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 200, 100)];
int i=arc4random()%100;
NSString *str1=@"本期参与:";
NSString *str2=[NSString stringWithFormat:@"%d",i];
NSString *str3=@"人次";
NSString *contentStr=[NSString stringWithFormat:@"%@%@%@",str1,str2,str3];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:contentStr];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5,str2.length )];
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:NSMakeRange(0, str2.length)];
label.attributedText = str;
[self.view addSubview:label];

运行结果:



转载请注明出处:http://blog.csdn.net/chen_gp_x
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: