我必须设置UIView的某些拐角半径,并通过此代码进行设置:
@IBDesignable
class MyUIviewCorner: UIView {
override func layoutSubviews() { setup() }
func setup() {
let r = self.bounds.size.height / 2
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft, .topRight],
cornerRadii: CGSize(width: r, height: r))
let mask = CAShapeLayer()
mask.backgroundColor = UIColor.clear.cgColor
mask.path = path.cgPath
layer.borderWidth = 1.5
layer.borderColor = UIColor.red.cgColor
self.layer.mask = mask
}
}
我不明白为什么。
为什么在上角半径上有此空白?
如果设置底角半径,我会得到:
您不应该为此使用掩码,您可以仅使用layer.maskedCorners
属性。
您可以看到为什么增加边框宽度的原因: