繁体   English   中英

剪切图像以适合图像视图

[英]Cut image to fit in image view

我有一个UIImageView,框架为320x240。

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
imgView.image = [self getImageFromServer:100];

我尝试了很多方法,但没有人为我带来结果。

该应用程序从服务器加载图像,但其中一些是320x320。

我必须如何剪切收到的图像? 这是削减,如果有人要无头出现,就不会发生。

问候

imgView.contentMode = UIViewContentModeScaleAspectFill;
imgView.clipsToBounds = true;

如果要始终保持大小,则可以将contentMode用作“ Center ,也可以将其调整为合适的大小,然后使用“ Scale Aspect Fit竞争模式进行裁剪。 您还需要剪切子视图。

您可以通过Interface Builder进行这两种操作:

设置内容模式:

在此处输入图片说明

将剪辑SubViews设置为YES:

在此处输入图片说明

或以编程方式:

//set the contentMode
imgView.contentMode = .contentMode = UIViewContentModeCenter;

//set clip subviews
test.clipsToBounds = YES;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM