UIButton 我需要创建一个带有弯曲边缘和边框的按钮,但我不确定该怎么做



我一直在谷歌上搜索,试图找到答案,但无法找到。我需要创建一个有圆形或弯曲边缘的臀部,并为其添加边框。我尝试过的都不起作用。请帮助

我建议向我们展示您已经尝试过的内容;也就是说,这是我使用的:

@IBDesignable class MyButton: UIButton
{
@IBInspectable var borderColor:UIColor? {
set {
layer.borderColor = newValue!.cgColor
}
get {
if let color = layer.borderColor {
return UIColor(cgColor:color)
}
else {
return nil
}
}
}
@IBInspectable var borderWidth:CGFloat {
set {
layer.borderWidth = newValue
}
get {
return layer.borderWidth
}
}

override func layoutSubviews() {
super.layoutSubviews()

updateCornerRadius()
}

@IBInspectable var rounded: Bool = false {
didSet {
updateCornerRadius()
}
}

func updateCornerRadius() {
layer.cornerRadius = rounded ? frame.size.height / 2 : 0
}
}

最新更新