贝塞尔路径绘制附加线
Bezier path drawing additional line
我正在使用贝塞尔曲线路径在 UI 按钮上添加圆角边框。
我总是有一条我不想要的额外线路。
代码在这里
let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
maskLayer.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft,.topRight], cornerRadii: CGSize(width: cornerRadius, height: 2)).cgPath
self.layer.mask = maskLayer
// Add border
let borderLayer = CAShapeLayer()
borderLayer.path = maskLayer.path // Reuse the Bezier path
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.lineWidth = 1
borderLayer.frame = self.bounds
self.layer.addSublayer(borderLayer)
截图
谢谢大家!
我会建议这个代码:
button.layer.borderWidth = 2.0
button.layer.borderColor = UIColor.white.cgColor
button.layer.cornerRadius = 5.0
button.layer.masksToBounds
我正在使用贝塞尔曲线路径在 UI 按钮上添加圆角边框。 我总是有一条我不想要的额外线路。
代码在这里
let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
maskLayer.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft,.topRight], cornerRadii: CGSize(width: cornerRadius, height: 2)).cgPath
self.layer.mask = maskLayer
// Add border
let borderLayer = CAShapeLayer()
borderLayer.path = maskLayer.path // Reuse the Bezier path
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.lineWidth = 1
borderLayer.frame = self.bounds
self.layer.addSublayer(borderLayer)
截图
谢谢大家!
我会建议这个代码:
button.layer.borderWidth = 2.0
button.layer.borderColor = UIColor.white.cgColor
button.layer.cornerRadius = 5.0
button.layer.masksToBounds