1

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.

  • you need to use UIBezierPath API provided by smart apple engineers. Create a class as subclass of UIButton, in storyboard give your button that class. Then in draw method make your design. – Tushar Sharma Nov 19 '17 at 16:40

1 Answers1

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

enter image description here

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