我有三个按钮,我想要围绕它:
我通过以下代码实现了这个目标:
button1.roundedButton1()
button2.roundedButton2()
button3.layer.cornerRadius = 5
extension UIButton {
func roundedButton1(){
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:5.0, height:5.0))
let maskLayer1 = CAShapeLayer()
// maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
}
func roundedButton2(){
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.bottomLeft , .bottomRight],
cornerRadii:CGSize(width:5.0, height:5.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
}
}
但我的第一和第二个按钮的宽度变得不安。
如果我使用button2.layer.cornerRadius = 5
,那么宽度就会变好。我已经搜索了哪个代码改变了它的宽度,但没有找到合适的东西。这是我为UIButton找到的唯一可行的解决方案。任何人都可以告诉我为什么按钮的宽度正在改变以及如何修复它?
按钮的约束如下: