【问题标题】:How to display large size image using UIImageView如何使用 UIImageView 显示大尺寸图像
【发布时间】:2018-02-04 14:16:21
【问题描述】:

在我的应用程序中,我有一个 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"]];

提前致谢

【问题讨论】:

    标签: ios objective-c uiscrollview uiimageview uiimage


    【解决方案1】:

    记得将图像视图添加为滚动视图的子视图。此外,您可以通过使用图像的大小来简化布局(在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;
    

    【讨论】:

      【解决方案2】:

      如果你想在水平和垂直方向上滚动图像,你可以按照 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;
      

      上面的代码只允许你在垂直方向上滚动。

      【讨论】:

      • 非常感谢。这个解决方案太棒了。 :) 这就是我想要的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 2014-11-19
      • 2021-11-23
      相关资源
      最近更新 更多