How to implement UIStepper with images

310 views Asked by At

I want to implement stepper with increasing and decreasing number of images. For example, in the beginning there is single image when plus sign is pressed new image is added to view in horizontal style. I thought to implement horizontal UICollectionView but collectionview should remain fixed not scrollable and after 5 new image wont be added to view. How could I implement a view like this?

1

There are 1 answers

0
Duncan C On

What you describe is completely custom.

I would suggest putting this logic in a self-contained view controller. Let's call it an ImageStepperViewController. The ImageStepperViewController can embed a UICollectionViewController.

Inside the ImageStepperViewController create a stepper. Set a maximum and minimum value. Attach an IBAction to the valueChanged event for the stepper. Have your view controller manage a collection view as well, and add/subtract image view cells to/from your collection view as the cell count goes up/down.

It shouldn't be that difficult.

You can then embed an ImageStepperViewController any place you need this functionality.

EDIT:

Note that if you don't need your collection of images to scroll you might consider using a horizontal (or vertical) stack view instead. Those are a lot easier to set up and manage. It only takes a few lines of code. I have a demo project that adds/removes views to a stack view on my Mac and I could upload it if you need help figuring out how to do it. (Mine doesn't use a stepper but that would be a simple modification.)