NSString*string = @"如何使得Label里的字符有不同的颜色?";
NSRange range = [string rangeOfString: @"Label"];
NSMutableAttributedString*attribute = [[NSMutableAttributedStringalloc] initWithString: string];
[attribute addAttributes: @{NSForegroundColorAttributeName: [UIColorredColor]}range: range];
[attribute addAttributes: @{NSForegroundColorAttributeName: [UIColorgreenColor]}range: NSMakeRange(0, range.location)];
[attribute addAttributes: @{NSForegroundColorAttributeName: [UIColorcyanColor]}range: NSMakeRange(range.location+ range.length, 5)];
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0.0f, 100.0f, 320.0f, 100.0f)];
[label setText: string];
[label setAttributedText: attribute];
字符串显示不同的颜色
最新推荐文章于 2024-11-27 14:38:29 发布
1306

被折叠的 条评论
为什么被折叠?



