0

new to iOS development. I'll explain the core purpose, the app should display an array of images on a horizontally scrolling view, these images will be loaded from the app documents itself. But the number of images stored in the app may vary from user to user. So, I want to create a horizontally scrolling view (UIScrollView/UITableView) which can hold UIImage. I want to change the width of the view as more images are read, but increasing the width of a UIScrollView wouldn't add a UIImage placeholder for the new images. OR Should I try with UITableView, any help would be much appreciated !

Dharmesh Dhorajiya
  • 3,976
  • 9
  • 30
  • 39

3 Answers3

1

Use UICollectionView instead of UIScrollView.

Check this SO link.

Here using collectView is easy as it has delegate method same as UITableView.

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0

You can use icarousel in ios https://github.com/nicklockwood/iCarousel

There are many types to choose from.

Hope that might help you !!!

aroragourav
  • 304
  • 3
  • 4
0

The best way is to start a UIScrollView, add it to your ViewController and write something like this:

self.scrollView.contentSize = CGSizeMake(self.pictures.count * 170 + 10, self.scrollView.frame.size.height);

Where the 170 for me is the width of the image + 10 (like to have some space between them). The +10 afterwards is 10px after my images too (end of the UIScrollView).

Later, to put on those images you can do

for (int x = 0; x < self.pictures.count; x++) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage"]];
        imageV.frame = CGRectMake(10 + x * 170, 10, 160, 120);
        [self.scrollView addSubview:imageV];
    }

Replace the imageNamed with your own image name or something like that...

This is only for about max 20 pictures, if you have a lot of pictures then I would suggest using a collection. multiple threads have started about those...

Yoko
  • 793
  • 10
  • 19