简体   繁体   English

iPhone下载图片并显示正确比例

[英]iPhone download images and display correct ratio

I'm downloading a bunch of images from a server and displaying them on the screen. 我正在从服务器下载一堆图像并将其显示在屏幕上。 I have about 320x450 to work with. 我有大约320x450可以使用。 Each image size has a different size, how do i correctly resize images so that they fit on the iphone screen and retain the correct ratio and the same time? 每个图像尺寸都有不同的尺寸,如何正确调整图像尺寸以使其适合iPhone屏幕并同时保持正确的比例?

使用您可以适合的任何大小的UIImageView ,并将其设置为与contentMode缩放:

myUIImageView.contentMode = UIViewContentModeScaleAspectFit;

Try this: 尝试这个:

UIImage *img = [UIImage imageNamed:@"image.png"];
imageview.frame=CGRectMake(x,y,img.size.width,img.size.height);
[self.view addSubView imageview];

尝试一下,以适应您的图像文件类型:

UIImage *img = [[UIImage imageNamed:@"image.png"] _imageScaledToSize:CGSizeMake(32.0f, 32.0f) interpolationQuality:1];

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

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