在IOS的图像视图中显示多个图像

时间:2017-07-24 05:40:11

标签: ios objective-c image

我在我的项目中使用ELCImagePickerController。通过它从库中选择多个图像。我面临的一个问题是,如何在视图控制器的图像视图中显示所选的多个图像。我创建了一个选择图像按钮,将我们带到photolibrary,我们选择多个图像。我的代码是,

 {
      "scripts": {
        "sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner.bat"
      }
    }

3 个答案:

答案 0 :(得分:1)

您可以使用CreolePhotoSelection来获取和选择多个图像。它将帮助您获得多个选择并将所有选定的值检索到委托方法。

以下是它的示例代码:

CreolePhotoSelection *objCreolePhotoSelection= [[CreolePhotoSelection alloc] initWithNibName:@"CreolePhotoSelection" bundle:nil];
objCreolePhotoSelection.strTitle = YOUR_TITLE_FOR_PHOTO_VIEW;
objCreolePhotoSelection.delegate = self; // It will help to retrive all selected photos from CreolePhotoSelection
objCreolePhotoSelection.arySelectedPhoto = YOUR_CURRENT_ARRAY; // You need to pass same array which is holding selected image
objCreolePhotoSelection.maxCount = YOUR_MAX_PHOTOS_LIMIT; // Eg. 5, 10 anythings...

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:objCreolePhotoSelection];
[self.navigationController presentViewController:navController animated:YES completion:nil];

// Delegate Method
#pragma mark - Photo selected Delegate Method
-(void)getSelectedPhoto:(NSMutableArray *)aryPhoto
{
  // You will selected image array into aryPhoto object and you can use it
}   

答案 1 :(得分:0)

首先,图像视图是显示单个图像。从你分享的代码中我不清楚你的意思是什么

 UIImage* image=[dict 
objectForKey:UIImagePickerControllerOriginalImage];

             _arrimage.image;

这个_arrimage是什么意思?这是对Image视图的引用吗?那应该是

_arrimage.image = image; //the image fetched in the above line

但这不会解决您的问题,因为这只会显示for循环中找到的最后一个对象(可能是最后选择的图像)。

要显示所有选定的图像,最好使用带有图像数组作为数据源的集合视图,并在集合视图的每个单元格中加载每个图像。

如果要在同一图像视图中显示所有图像,可以通过将其设置为animationimages来提供另一个选项

imageView.animationImages = imagesListArray //the list of image you selected
imageView.animationDuration = 2.0
imageView.startAnimating()

这只是从阵列中一次一个地显示每个图像,时间间隔为2秒

答案 2 :(得分:0)

You can't Show Multiple Images in a single ImageView at a same time but yes you can show multiple images on a same ImageView for sometime using Image Animation.

var imagesArray = [UIImage]()

for imageName in 1...3
{
    imagesArray.append(UIImage(named: "\(imageName).png")!)
}

// You can also use below code to add images if not want to use loop    
// imagesArray.append(UIImage(named: "a.png")!)
// imagesArray.append(UIImage(named: "b.png")!)
// imagesArray.append(UIImage(named: "c.png")!)

self.imageView.animationImages = imagesArray
self.imageView.animationDuration = 2.0
self.imageView.startAnimating()