1

I have an ImageView which is already resized to be a circle, and it contains an image inside, which is already fitted to fill the circle. The only problem is when I open the image in another part of my app it is not a circle but rather in its original form. This is because I didn't resize the image, but rather the ImageView. So my question is how can I crop the image to be the same as it looks (a circle)? Or, if there's a better solution to this like resizing the image rather than the View I would love to hear it!

Here is the code I'm using to resize the ImageView:

self.profilePic.layer.cornerRadius = (self.profilePic.frame.size.height+20)/ 2;
self.profilePic.layer.masksToBounds = YES;
self.profilePic.clipsToBounds = YES;
Lehman2020
  • 637
  • 7
  • 22

1 Answers1

0

How about this?

self.profilePic.contentMode = UIViewContentModeScaleAspectFill;
Lucifer
  • 480
  • 3
  • 12
  • Can you show some more code? Especially how you resize the UIImageView and how you fit the UIImage in it. – Lucifer Jul 04 '15 at 19:40
  • [self.profilePic setImage:image]; I use this to fit the image inside, and the code for resizing the ImageView is above, profilePic is my imageView – Lehman2020 Jul 04 '15 at 19:43
  • Or why don't you subclass the UIImageView. Then in `-drawRect:` method make the corner rounding. And then override the setter for the image `-setImage:` and make the resize there. – Lucifer Jul 04 '15 at 19:44