I have a button that is rounded in all four corners since I used the User Defined Runtime Attributes panel to make it rounded... but once running the application I saw that the button would be better off if only the right side was rounded and the left side was just squared. Is there a way I can do this? I am using Xcode 9.1 and Swift 4.
Asked
Active
Viewed 528 times
1 Answers
1
All you need is
let path = UIBezierPath(roundedRect: self.testButton.bounds, byRoundingCorners:[.topRight, .bottomRight], cornerRadii: CGSize(width: 10, height: 10))
let maskLayer = CAShapeLayer()
maskLayer.frame = self.testButton.bounds
maskLayer.path = path.cgPath
self.yourButton.layer.mask = maskLayer
O/P will look like
You said
I saw that the button would be better off if only the right side was rounded and the left side was just squared
Did not mention clearly is both top and bottom right corner will be rounded or not so I took a liberty to imagine the same. You can choose whatever you want by modifying
[.topRight, .bottomRight]
value I specified in code above

Sandeep Bhandari
- 19,999
- 5
- 45
- 78