您的位置:首页 > 其它

解决CATextLayer绘制出来的字体模糊问题

2016-03-31 11:56 387 查看
最近项目中使用到CATextLayer.可是碰到绘制出的字体模糊的问题.现将解决后的代码贴上来:

CATextLayer *textLayer = [CATextLayer
layer];
textLayer.string =
@"楼梯";
textLayer.font = (__bridge
CFTypeRef _Nullable)([UIFont
systemFontOfSize:14]);
textLayer.fontSize =
20;
textLayer.foregroundColor = [UIColor
redColor].CGColor;
CGSize size = [@"CATextLayer"
boundingRectWithSize:CGSizeMake(self.view.bounds.size.width,
MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : [UIFont
systemFontOfSize:20]}
context:nil].size;
textLayer.bounds = (CGRect){{0,0},size};
textLayer.position =
CGPointMake(100,
100);

textLayer.contentsScale = [UIScreen
mainScreen].scale;// 这句话使得字体不模糊,这是因为屏幕的分辨率问题,参照图片@1x. @2x. @3x .改为相应数字就可以
[self.view.layer
addSublayer:textLayer];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: