-1

How can I programmatically apply a circular crop out to a UIImage or a UIImageView? Is it possible, or must I use a graphical mask?

Till now I am using a graphical mask (a png image) but the final crop out result is ovalized, rather than a perfect circle.

[imageView setContentMode: UIViewContentModeScaleAspectFit];

[imageView setContentMode: UIViewContentModeScaleAspectFill];

also do not solve the problem.

Please note that the UIImageView that the image is applied to is already defined exactly as a square in IB.

jscs
  • 63,694
  • 13
  • 151
  • 195
jeddi
  • 651
  • 1
  • 12
  • 21
  • 1
    "Till now I am using a graphical mask (a png image) but the final crop out result is ovalized, rather than a perfect circle” But we cannot tell you what you are doing wrong if you don’t show the code by which you’re doing that. Do you know what an MCVE is? You need to, in order to ask a decent question on Stack Overflow. – matt Mar 18 '19 at 18:29

1 Answers1

0

If the UIImageView is already a square then you can set the corner radius of its layer to half of its width/height

[imageView.layer setCornerRadius:imageView.frame.size.width / 2.0]; 
[imageView.layer setMasksToBounds:YES];