如何从图像中检测尺寸,并使用该尺寸创建一个UIImageView,使图像完美地适应其中?
只需按照以下方式创建UIImageView:
UIImageView *aImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]];
因此,ImageView的大小与图像的大小相同。根据UIImageView的文档:
该方法会调整接收器的框架大小以匹配指定图像的大小。默认情况下,它还会禁用图像视图的用户交互。
希望我的答案对你有所帮助。:-D
Sandro
当我们在imageView中使用图像时,无需设置帧大小
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
ImageView 会自动获取图片的尺寸。