Crop an Image to the size of an ImageView

2019-08-10 21:24发布

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;

1条回答
可以哭但决不认输i
2楼-- · 2019-08-10 21:52

How about this?

self.profilePic.contentMode = UIViewContentModeScaleAspectFill;
查看更多
登录 后发表回答