CALayer:单像素行看起来像2像素 [英] CALayer: Single pixel line looks like 2 pixels
本文介绍了CALayer:单像素行看起来像2像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
int columns 3;
int columnWidth = self.layer.bounds.size.width / 3;
for (int c = 1; c < columns; c++) {
CALayer *layer = [CALayer layer];
layer.frame = (CGRectMake(columnWidth * c + 0.5, 0.5, 1, self.layer.bounds.size.height));
layer.backgroundColor = myColor;
[grid addSublayer:layer];
}
我理解我必须移动x和y 0.5像素,这是我已经做了,但它仍然显示为2像素线而不是1。
I understand that I have to shift the x and y 0.5 pixels, which is what I have done, yet it still shows as a 2 pixel line instead of 1.
推荐答案
将图层框架设置为
layer.frame = (CGRectMake(columnWidth * c + 0.5, 0.5, 0.5, self.layer.bounds.size.height));
是的,它也适用于视网膜。
Yeah it will work for retina also
查看此帖子部分 1点线和像素边界。很好地解释了
Check this post Section 1 Point Lines and Pixel Boundaries.It is well explained there
这篇关于CALayer:单像素行看起来像2像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文