将图像裁剪为ImageView的大小 [英] Crop an Image to the size of an ImageView

查看:131
本文介绍了将图像裁剪为ImageView的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经调整为圆形的ImageView,它包含一个内部图像,已经适合填充圆圈。唯一的问题是当我在我的应用程序的另一部分打开图像时,它不是一个圆形而是它的原始形式。这是因为我没有调整图像大小,而是调整了ImageView。所以我的问题是如何裁剪图像与它看起来一样(圆圈)?或者,如果有更好的解决方案,比如调整图像大小而不是View,我很乐意听到它!

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!

以下是我用来调整ImageView大小的代码:

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;


推荐答案

这个怎么样?

self.profilePic.contentMode = UIViewContentModeScaleAspectFill;

这篇关于将图像裁剪为ImageView的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆