UILabel *sendNameLB = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
NSString * string = @"*姓名";
sendNameLB.text = string;
NSMutableAttributedString *richText = [[NSMutableAttributedString alloc]initWithString:string];
[richText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[string rangeOfString:@"*"]];
[sendNameLB setAttributedText:richText];
[self.view addSubview:sendNameLB];

最近在写一个必填选项的提示符,类型‘*姓名’这样 *还要红色。发现字符串的attributedText属性可以搞定。记录一下

来源:http://blog.csdn.net/qq_29892943/article/details/51859393

感谢作者

04-28 00:54