UIScrollView中的多张图片

3

我在视图中有一个 UIScrollView。同时,我也有一个包含图片的数组,现在我想在滚动视图中显示这些图片。由于我是新手,如果有人能帮助我,我将非常高兴。

NSMutableArray *images = [[NSMutableArray alloc ] init];

for (int i = 0; i < 10; i++)
{
    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString     stringWithFormat:@"%d/%d.png",b, i]];
    UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
    [images addObject:img];
    NSLog(@"%@",getImagePath);
    imge.image=img;
}
1个回答

4

您需要设置您的UIScrollViewcontentSize; 并将您的UIImageView添加到您的ScrollView中,例如:

[self.myScView addSubView:self.imageView];

您需要在单独的 UIImageView 上添加图像
阅读此 UIScrollView 的基础知识。

我只想在这里表达我的逻辑:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    self.scrollView.contentSize = CGSizeMake(320, 465);
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];

    int Y = 0;

   // here give you image name is proper so we can access it by for loop.
    for (int i = 1; i <=  totalNumberOFImage; i++)
    {
      UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, Y, 100, 100)] ;
      [imageView setImage: [UIImage imageNamed:[NSString stringWithFormat:@"youImageName%d", i]]];
      [self.scrollView addSubview: imageView];
      Y = Y + imageView.frame.size.height+5;

     if(y > 465)
      self.scrollView.contentSize = CGSizeMake(320, y);
    }
}

按照以下代码进行操作可能会有帮助:


你能否给我发送一个全面的解决方案。 - Nasir
请遵循我的回答。 - iPatel
这里的imgLogo是什么? - Nasir
抱歉,这是我的错误,请在此处添加您的ImageView名称。我已编辑了我的答案。 - iPatel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接