您的位置:首页 > 其它

一个Label中显示不同的字体颜色

2016-11-24 10:48 316 查看
NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:@"红色黑色蓝色绿色"];

    [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];

    

    [string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(2, 2)];

    [string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(4, 2)];

    [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(6, 2)];

    self.lab.attributedText = string;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: