UILable更改部分字体颜色

2018-08-03  本文已影响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;

上一篇 下一篇

猜你喜欢

热点阅读