【发布时间】:2019-02-23 09:02:27
【问题描述】:
如何为具有不同圆角的 UIBezierPath 获得干净的 1 px 边框?
在下面的示例中,我使用了 3 个角。代码在 UIView 内:
let borderLayer = CAShapeLayer()
borderLayer.frame = bounds
borderLayer.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.topRight, .bottomLeft, .bottomRight], cornerRadii: CGSize(width: 24, height: 24)).cgPath
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.lineWidth = 1
borderLayer.strokeColor = UIColor.white.cgColor
layer.addSublayer(borderLayer)
结果在角度上有宽度问题:
【问题讨论】:
-
我看起来可能图层被剪裁到了边界,只显示了边缘的一半。
-
我在 iOS 10 中测试过,没有任何问题。 imgur.com/a/J7RB7EI
-
@QuocNguyen 好的,可能是由 superview 剪辑引起的。这是一个 UITableViewCell。插入路径的 JonJ 解决方案解决了我的问题。
标签: ios swift uibezierpath rounded-corners cashapelayer