ios - SizeToFit on UIImageView not working

流过昼夜 提交于 2019-12-05 14:19:31

Check the image size:

NSLog(@"%@", NSStringFromCGSize(imageView.image.size));

You may want to set imageView frame based on the image size manually, for example, if the image is too large to fit the imageView's superview.

UIImageView *myImage = [[UIImageView alloc]init];
myImage.contentMode = UIViewContentModeScaleAspectFit;
myImage.image = [UIImage imageName:@"image.png"];
[self.view addSubview:myImage];

sizeToFit should work in your situation, but fails if the UIImage is nil.

UIImage's imageWithContentsOfFile: returns a (completely loaded) reference to a UIImage or nil. Are you sure that you're passing the right path?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!