美文网首页
UILable更改部分字体颜色

UILable更改部分字体颜色

作者: 我一不小心就 | 来源:发表于2018-08-03 12:00 被阅读0次

UILabel *label = [[UILabel alloc] init];
label.textColor = TextGrayColor;
label.font = [UIFont systemFontOfSize:12];

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"网址是:https://www.baidu.com"];
//更改字体
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20] range:NSMakeRange(4, 21)];
//修改颜色
[string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(4, 21)];

label.attributedText = string;

相关文章

网友评论

      本文标题:UILable更改部分字体颜色

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