- 创建UILable
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(10, 70, 200, 40)];
label.numberOfLines=3;
label.font=[UIFont systemFontOfSize:14];
[self.view addSubview:label];
- 拼接字符串
NSString *str=[NSString stringWithFormat:@"文档规范提醒\n发布注意事项通知"];
NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:str];
NSInteger length=@"文档规范提醒\n".length;
NSInteger tatolLength=@"发布注意事项通知".length;
NSRange wordRange= NSMakeRange (length, tatolLength);
[string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:wordRange];
[string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:wordRange];
[label setAttributedText:string];