在我的应用程序中,我有一个 800 x 2000 的大尺寸图像。我想在 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);
还有这个:
self.aScrollView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"About_CVR_Detail"]];
提前致谢
如果你想在水平和垂直方向上滚动图像,你可以按照 danh 说的做。
但是如果你只想滚动一个方向,你应该设置固定的宽度或高度,并保持比例,还应该计算另一个长度。
例如:
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;
上面的代码允许您仅在垂直方向上滚动。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句