Search code examples
iosswiftcalayer

Circular UIView achieved with cornerRadius looks blocky


In my application, I usecornerRadius to apply a circular mask effect to a UIView.

view.layer.cornerRadius = view.frame.height / 2
view.clipsToBounds = true

However, when I use this method, the result looks blocky. I enlarged this example of the issue, so the issue can be seen better (especially on the top):

An example of the blockiness with a plain black image.

What causes this and how can I fix this?


Solution

  • Modify your UIView's frame size: change every value to a whole number, so the graphics engine can calculate the image with a perfect result.