您的位置:首页 > 移动开发 > IOS开发

[ios]字符串不同位置显示不同颜色

2016-05-13 14:10 381 查看
NSString* str=@“颜色分段显示”;

    NSMutableAttributedString *coloredStr = [[NSMutableAttributedString
alloc]
initWithString:str];

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

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

效果为  “颜色”显示红色    “分段显示”显示黑色。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: