Thursday, April 30, 2020

Create UICollectionView Like Instagram When Exploring Photos


Hello guys, I hope you're doing well. I was doing research about how to make my UICollectionView like Instagram. As you can see on picture above. I have time to search on the internet but somehow I want to custom it by myself. I mean I don't want to use framework.

After I finished my custom UICollectView, I found IGListKit framework for building fast and flexible lists. But I haven't used it Because I think it's not for custom layout UICollectionView. But if I have much time maybe I will try to use that framework. I think it's cool to use framework that's built by iOS Instagram Developer.

What I want to share is a  custom class UICollectionViewLayout called SavedCollectionViewLayout. Because I used this class to show my saved collection photos. But you can edit the name as you want, no problem at all. But I think there's a room for improvement this class. If you have any idea to improve this code. Tell me. I'm glad I have someone to improve my code quality.
I make sure you already understand UICollectionView literally. And You ever create one eventhough it's simple. But that's all you need basic knowledge and curiosity of course :D. First you need to create your own custom CollectionViewLayout. I named my class SavedCollectionViewLayout. The code I give a long code. And I think you can improve. If I have time I will try to figure it out more.



My main idea is to create 18 different columns. Because we need to handle x,y position and height,width size. We need to use modular to catch same column that has same position or width, so it would not make too much codes. The logic part is in prepare method. Basically we loop every collection cell and we check it where the size and position will be based on IndexPath.

Method getSizeColumn used to set my UIImageView size when I call it in my cellForItemAt UICollectionViewDataSource. Because sometimes the images size is not correct. I just want to make sure my UIImageView size is correct. Sometimes it will show message in console that said our UIImageView size in cell is too big.

So If you have any question, please feel free to ask. Soon I will release my first iOS app on AppStore. So you can see what I build. Maybe you can give a good idea to improve that app. Thanks for visiting my simple blog. Have a nice day guys.

No comments:

Post a Comment