Search code examples
swift4rounded-corners

Corner radius just in particular corner


I am working in Swift 4 and I am trying to make a button with just two of the four corners rounded (for some buttons the top-right and button right and for some the top-left and bottom-left corners).

I've search a lot and all that I've found is this: myButton.layer.cornerRadius = newCornerRadiusInPixels;. It works perfectly but it roundes all the corners at the same time.

is there a way to round just a particular corner? Thanks!


Solution

  • Available in iOS 11 and up:

    myButton.layer.maskedCorners = [.layerMaxXMaxYCorner]  // or some other corner(s)