IOS中来自服务器的映像大小问题

IOS中来自服务器的映像大小问题,ios,objective-c,iphone,ios8,Ios,Objective C,Iphone,Ios8,我正在开发一个应用程序,其中图像来自服务器,我必须在UIImageview中显示,其大小与屏幕大小相同。问题是有些图像的分辨率非常大。因此,当我使用AspectFill时,它没有正确显示,它正在收缩,当我使用AspectFit时,它在图像视图中以矩形显示。所以,有没有办法在UIImageView中显示图像而不收缩和交叉 提前感谢试试这个 -(UIImage*)resizeImage:(UIImage *)image imageSize:(CGSize)size { UIG

我正在开发一个应用程序,其中图像来自服务器,我必须在
UIImageview
中显示,其大小与屏幕大小相同。问题是有些图像的分辨率非常大。因此,当我使用AspectFill时,它没有正确显示,它正在收缩,当我使用AspectFit时,它在图像视图中以矩形显示。所以,有没有办法在
UIImageView
中显示图像而不收缩和交叉

提前感谢

试试这个

-(UIImage*)resizeImage:(UIImage *)image imageSize:(CGSize)size
    {
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0,0,size.width,size.height)];
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        //here is the scaled image which has been changed to the size specified
        UIGraphicsEndImageContext();
        return newImage;

    }
然后将新图像用于您的
imageView

您可以使用

UIImage * image=[UIImage imageNamed:@"image.png"];
CGSize size=CGSizeMake(50, 63);//set the width and height 
UIImage resizedImage= [self resizeImage:image imageSize:size];

希望有帮助。

我认为将contentMode更改为UIViewContentModeScaleToFill您的imageView应该会有所帮助:

yourImageView.image = yourImage;
yourImageView.contentMode = UIViewContentModeScaleToFill;

CGRect frame = someImageView.frame;
frame.size = yourImage.size;
yourImageView.frame = frame;
尝试:


我希望这会有帮助。

我认为没有办法,但对于图像来说,你应该只适合侧面。
UIImageView  *yourImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
yourImageView.contentMode = UIViewContentModeRedraw;
yourImageView.image = yourImage;