如何根据图像的大小动态设置imageView的大小 [英] How can I dynamically set the size of the imageView according to the size of the image

查看:433
本文介绍了如何根据图像的大小动态设置imageView的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Interface Builder来布局我的视图和图像视图。我在视图上放了一个imageView并将其设置为插座。问题是无论我在我的程序中设置了什么尺寸的图像(768 * 1024,1024 * 700):

I user Interface Builder to layout my view and image view. I put a imageView on the view and set it as an outlet. The problem is that no matter what size of image (768*1024、1024*700) I set in my program:

 self.imageView.image = [UIImage imageNamed:self.filename];

屏幕上的大小始终是我在Interface Builder中设置的imageView的大小。如何根据图像的大小动态设置imageView的大小?谢谢!

The size to be on the screen is always the size of the imageView I set in the Interface Builder. How can I dynamically set the size of the imageView according to the size of the image? Thanks!

推荐答案

类似于:

UIImageView *imageView = [[UIImageView alloc] init];

UIImage *image = [UIImage imageNamed:@"image.png"];
CGSize imageSize = [image size];

imageView.frame = CGRectMake(0, 0, imageSize.width, imageSize.height);

这篇关于如何根据图像的大小动态设置imageView的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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