如何在圆形按钮上更改边框颜色(Swift)

时间:2018-02-10 08:14:40

标签: ios swift uibutton

我有四个按钮。

两个按钮有圆角(1-(左上,左下),4-(右上,右下))

如何在图像上更改边框颜色。

// Right Button
let T1 = UIBezierPath(roundedRect:Delete.bounds, byRoundingCorners:[.topRight, .bottomRight], cornerRadii: CGSize(width: 15, height:  15))
    let maskLayer = CAShapeLayer()
    maskLayer.path = T1.cgPath
    Delete.layer.mask = maskLayer
// Left Button
let T2 = UIBezierPath(roundedRect:Copy.bounds, byRoundingCorners:[.topLeft, .bottomLeft], cornerRadii: CGSize(width: 15, height:  15))
    let maskLayer2 = CAShapeLayer()
    maskLayer2.path = T2.cgPath
    Copy.layer.mask = maskLayer2

3 个答案:

答案 0 :(得分:4)

添加您的UIView" containerView"设为IBOutlet并设置containerView.layer.borderWidth = yourDesiredWidth并设置containerView.layer.borderColor = yourNeededColor.cgColor

答案 1 :(得分:2)

UIButton.layer.cornerRadiusUIButton.layer.borderColorUIButton.layer.borderWidthlayerUIView的属性,因此您可以使用它自定义任何视图。

答案 2 :(得分:1)

button.layer.borderColor = CGColor(srgbRed: 255/255, green: 126/255, blue: 121/255, alpha: 1)
相关问题