SWIFT - Setting layer.cornerRadius greater than the view height causes issues

Viewed 83

I actually want to add a corner radius to a view on only one side. The radius is supposed to be of full height. This is my implementation.

someView.layer.cornerRadius = someView.frame.size.height
someView.layer.maskedCorners = [.layerMaxXMaxYCorner]

This does the job as required, but it adds extra shapes on other sides as shown below.

What might be the problem? enter image description here

1 Answers

This looks like an iOS bug, I was able to reproduce it

But usually you don't wanna set cornerRadius greater than half view minimum side, in your case:

someView.layer.cornerRadius = someView.frame.size.height / 2

I assume it'll produce result you're expecting:

enter image description here

Corner radius is radius of a circle inscribed in the corner of a rectangle, I think that's why there may be problems with radius bigger than side/2: circle doesn't fit a rectangle anymore

Related