我将背景颜色设置为白色边框,边框从背景中渗出。我希望蓝线消失。你能建议这个问题的解决方案吗?
下面是我的代码。下面是我正在谈论的图像。
[
self.imageView.layer.borderColor = UIColor.white.cgColor
self.imageView.layer.borderWidth = 3
self.imageView.backgroundColor = UIColor.blue
self.imageView.layer.cornerRadius = CGFloat(CircleDiameter/2)
我想这就是 iOS 渲染对具有正 cornerRadius 的图层所做的,我测试过添加一个白色圆 View 与具有相同大小的蓝色圆 View 重叠,出现相同的情况:
其实通过borderWidth Document层的边界是从接收者的边界绘制的,所以它和我上面提到的情况是一样的:
When this value is greater than 0.0, the layer draws a border using the current borderColor value. The border is drawn inset from the receiver’s bounds by the value specified in this property. It is composited above the receiver’s contents and sublayers and includes the effects of the cornerRadius property.
因此边框 + 圆度 = iOS 上的悲伤,我认为您需要另一种方式来实现您的设计。