Scrollable Photo Gallery with add, remove image abilities for iOS

  • Sharebar

Mobile apps are effectively distinguished by the way they present content to the user. Content that can act as a catalyst in inference of the information that is being supplied to the user. Understandingly photos are one of the most powerful tool to serve this purpose. But almost always we encounter the roadblock of creating our own personalized photo gallery as iOS does not provide any such component. Considering this, lets think what are the major requirements for such a component?
Well, I find following possibilities
     

  • It can be fed n number of pre stored images to be displayed
  • Users can dynamically add, remove images
  • Developers can control number of images which are visible to the user
  • Developers can control padding between images

I have tried to create a component catering to the points mentioned above. You can get your hands dirty on it here. After integrating it looks like this

XePhotoGallery with add/remove image feature
 
 
 

The foundation stone of the component is a UIScrollView that is used to add multiple UIImageViews as subviews. The following code is used to display pre stored images.

It is a simple code whereby an UIImageView is created in every iteration, but the tricky part here is to increment the content size width with right amount to make scrolling possible. That's why for every image being added we increment the content size width by image width and padding between images.

Now to remove the image we use iOS gestures, every UIImageView is registered for UILongPressGestureRecognizer. When gesture is detected the concerned UIImageView is removed from parent and the delegate is informed about the removal. The removal process is animated to give a soothing experience. Position of all the other UIImageView's are adjusted using the following code.

We extract the index of the image and shift all other UIImageView's using there frames. Also we decrement the content size width.

Currently the photo gallery can only show images in a single row. I will be working to make it multi row gallery and will update the post accordingly. You can also give it a try and add more features as you may find useful.

Leave a Reply

You must be logged in to post a comment.