I know how to round both sides of a UIButton with: myButton.layer.cornerRadius = 10, but I am not sure how to round just one side so it would look something like this:
Asked
Active
Viewed 179 times
-1

beep
- 9
-
Please check: https://stackoverflow.com/a/37164262/15161794 – Kush Bhavsar Jun 30 '22 at 17:01
-
Does this answer your question? [Round Top Corners of a UIButton in Swift](https://stackoverflow.com/questions/37163850/round-top-corners-of-a-uibutton-in-swift) – Anish Jun 30 '22 at 17:22
2 Answers
1
I don't think you can do it in IB, the usual way to do it would be to either set properties or manually via the User Defined Runtime Attributes.
However, setting the a corner radius but only for certain corners requires setting the layer maskedCorners array with values ([.layerMinXMinYCorner, .layerMinXMaxYCorner]) and that is not supported in IB.
The other option would be to write a subclass of UIButton that sets those values in the init method (particularly the init(coder:)) and then change in IB to use that class for the view.

Alex Germán
- 31
- 5
0
Use this extension into your project
extension UIButton {
func roundCorners(corners: UIRectCorner, radius: Int = 8) {
let maskPath1 = UIBezierPath(roundedRect: bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = bounds
maskLayer1.path = maskPath1.cgPath
layer.mask = maskLayer1
}
}
to call roundCorners Method
myButton.roundCorners(corners: [.topLeft, .bottomLeft])
If you need to use extension for all view components
Change extension UIButton
to extension UIView

El-Dow
- 222
- 2
- 12