B2Fq
B2Fq

Reputation: 916

How change border color on round button (Swift)

i have four button.

And two button have round corner (1-(top Left, bottom Left),4-(top Right, bottom Right)).

How can i change border color how on image.

// 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

Upvotes: 2

Views: 1431

Answers (3)

Fahim Rahman
Fahim Rahman

Reputation: 227

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

Upvotes: 1

Reinier Melian
Reinier Melian

Reputation: 20804

Add your UIView "containerView" as IBOutlet and setup your containerView.layer.borderWidth = yourDesiredWidth and setup the containerView.layer.borderColor = yourNeededColor.cgColor

Upvotes: 4

Son Nguyen
Son Nguyen

Reputation: 1634

UIButton.layer.cornerRadius, UIButton.layer.borderColor, and UIButton.layer.borderWidth. layer is a property of UIView, so you can pretty much customize any view with it.

Upvotes: 2

Related Questions