【问题标题】:how to use uiimageview to view image from an array如何使用 uiimageview 从数组中查看图像
【发布时间】:2012-06-01 11:08:36
【问题描述】:

我创建了一个包含一组照片的应用程序。 我有一个 UIImageView 对象,我想将数组中的图像显示到我的 imageview 中。 我该怎么做?

我的数组声明:

     photoArray = [[NSMutableArray alloc] init];
     PhotoItem *photo1 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"1.jpg"] name:@"roy rest"  photographer:@"roy"];
     PhotoItem *photo2 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"2.jpg"] name:@"roy's hand" photographer:@"roy"];
     PhotoItem *photo3 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"3.jpg"] name:@"sapir first" photographer:@"sapir"];
     PhotoItem *photo4 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"4.jpg"] name:@"sapir second" photographer:@"sapir"];
     [photoArray addObject:photo1];
     [photoArray addObject:photo2];
     [photoArray addObject:photo3];
     [photoArray addObject:photo4];

另一个问题: 我如何编写一个代码来创建一个 uiimageview 作为我数组中对象的编号??

谢谢!!

【问题讨论】:

  • 你想如何显示图像?在单个图像视图或 4 个图像视图中?

标签: objective-c xcode arrays uiimageview nsmutablearray


【解决方案1】:

请参考下面,让我知道它是否有用?

for(PhotoItem *photoItem in photoArray){
        UIImageView *imgView = [[UIImageView alloc] initWithImage:photoItem.imageProperty];
     [self.view addSubview:imgView];
    }

【讨论】:

    【解决方案2】:

    您可以将 UIImageView 对象添加到 uiscrollView,然后添加 uiscrollView 对象,即滚动到视图...

        int y = 10;
        for (UIImage *img in array) {
            UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, y,200, 400)];
            [imgView setImage:img];
            [scroll addSubview:imgView];
            y = y + imgView.frame.size.height + 5;
        }
        [scroll setContentSize:CGSizeMake(300, y)];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多