我正在使用bezier路径在我的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)
谢谢你们!
答案 0 :(得分:1)
我会建议这段代码:
button.layer.borderWidth = 2.0
button.layer.borderColor = UIColor.white.cgColor
button.layer.cornerRadius = 5.0
button.layer.masksToBounds