iphone - UIScrollView 中的多个图像

标签 iphone ios objective-c uiscrollview

我的 View 中有一个 UIScrollView。还有一个包含图像的数组,现在我想在 ScrollView 中显示该图像。如果有人帮助我,我是 iPhone 的新手。我会很高兴。

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;
}

最佳答案

你需要设置contentSize你的 UIScrollView; 并将您的 UIImageView 添加到您的 ScrollView,例如

[self.myScView addSubView:self.imageView];

并且您需要在单独的 UIImageView 上添加image
阅读 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);
    }
}

遵循此代码可能对您的情况有帮助:

关于iphone - UIScrollView 中的多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17761309/

相关文章:

iphone - 导航栏出现在带有新 iOS7 SDK 的 View 上

iphone - 在 iPhone 上下载 XML 文件,存储它然后使用它

ios - 在两个 UIButton 图像之间淡入淡出

iOS 核心数据 : How do I add subsequent records to the 'many' of 1:many relationships?

objective-c - 有没有检查 UIViewController 是否出现的好方法?

ios - 应用程序在加载模态窗口时崩溃

ios - 在两种不同类型的 UITableViewCells 之间交替

iphone - NSInvocation需要NSMethodSignature

iOS Tap 手势状态开始不命中

ios - 在我导入 xcassets 后, Storyboard对每张图片都有问号