您的位置:首页 > 其它

重绘Label实现字体的各种变化 颜色 字体大小 下划线

2014-03-05 20:20 441 查看

CATextLayer字体模糊问题

把其中的几个字变深色一点或者变颜色,代码如下:

NSMutableAttributedString *attriString = [[[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Promotion", nil)]
autorelease];
[attriString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor colorWithRed:255 green:200 blue:0 alpha:1].CGColor range:NSMakeRange(0,124)];
[attriString addAttribute:(NSString *)kCTForegroundColorAttributeName
value:(id)[UIColor redColor].CGColor
range:NSMakeRange(124, 6)];
[attriString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor colorWithRed:255 green:200 blue:0 alpha:1].CGColor range:NSMakeRange(130,10)];
CATextLayer *textLayer = [CATextLayer layer];
textLayer.string = attriString;
textLayer.fontSize=15;
textLayer.frame = CGRectMake(0, 20, 280, 160);
textLayer.backgroundColor=[[UIColor clearColor]CGColor];

//需要设置CALayer的contentsScale属性。这个值来自于屏幕的backingScaleFactor, contentsScale = 2表示retina屏幕; textLayer.contentsScale = 2;
[whiteBackground.layer addSublayer:textLayer];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐