如何使用UIImageView显示大尺寸图像

问题描述:

在我的应用程序中,我有一个大尺寸图像800 x 2000.我想在UIImageView中显示此图像,此图像也是可滚动的。如何使用UIImageView显示大尺寸图像

我试过下面的代码。

UIImage *img=[UIImage imageNamed:@"About_CVR_Detail"]; 
self.aImgView.frame=CGRectMake(0,0, Screen_Width,img.size.height); 
self.aImgView.image=img; 
self.aScrollView.contentSize=CGSizeMake(Screen_Width, self.aImgView.frame.size.height); 

,也将ty这其中也:

self.aScrollView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"About_CVR_Detail"]]; 

在此先感谢

如果要滚动的图像无论是水平还是垂直,你可以像丹说的那样做。

但是,如果你只想要一个定位滚动,你应该设置固定的宽度或高度,并保持比例,也应该计算其他长度。

例如:

UIImage *img=[UIImage imageNamed:@"image.png"]; 
self.aImgView.frame=CGRectMake(0,0, Screen_Width, Screen_Width * img.size.height/img.size.width); 
self.aImgView.image=img; 

[self.aScrollView addSubview:self.aImgView]; 
self.aScrollView.contentSize= self.aImgView.frame.size; 

上面的代码允许你滚动仅在垂直oritation。

+0

非常感谢你。这个解决方案非常棒。 :)这是我想要的 –

记住图像视图添加为滚动视图的孩子。此外,您还可以通过使用图像的大小(它设置了图像视图中initWithImage,其范围可用于滚动视图contentSize)简化布局..

UIImage *img=[UIImage imageNamed:@"About_CVR_Detail"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:img]; 

[self.aScrollView addSubview:imageView]; 
self.aScrollView.contentSize = imageView.bounds.size;