如何使得Label里的字符有不同的颜色
1个回答
推荐于2016-08-31 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517183
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
[upload=1] [upload=1] iOS6.0有一个attributedText属性,可以参考。再或者就是drawrect自己绘制吧
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];
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];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询