self.layer.borderWidth = 0.5;
在UIButton
或UITextField
上,视网膜屏幕上呈现罚款,但在非视网膜屏幕上,只有顶部和左侧边框呈现,而右侧和底部边框不呈现。
我认为这与屏幕的dpi和如何绘制子点线有关,但是有可能有更好的解释。
问题:,我想知道是否有可能像预期的那样在borderWidth
设置为0.5
的视网膜和非视网膜屏幕上显示UIView
的所有边框。
发布于 2013-06-12 13:34:24
如果您希望始终使用单个像素(而不是点)线,则必须根据屏幕的比例使用不同的边框宽度。
例如:
CGFloat scale = [[UIScreen mainScreen] scale];
if (scale == 2.0) {
// retina screen;
self.layer.borderWidth = 0.5;
} else {
// non-retina screen
self.layer.borderWidth = 1.0;
}
发布于 2014-11-21 16:25:59
既然支持多个比例尺(@3x),最好将Matt的答案写成这样:
CGFloat scale = [[UIScreen mainScreen] scale];
CGFloat width = scale > 0.0 ? 1.0 / scale : 1.0;
[self.layer setBorderWidth:width];
https://stackoverflow.com/questions/17075289
复制