修改UILabel的某一部分顏色需要用到NSMutableAttributedString
UILabel *label = [[UILabel alloc] init]; label.textColor = TextGrayColor; label.font = [UIFont systemFontOfSize:12];NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"網(wǎng)址是: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;新聞熱點
疑難解答