1

I'm using this library, CHTCollectionViewWaterfallLayout (https://github.com/chiahsien/CHTCollectionViewWaterfallLayout) to try to replicate a feed that's similar to the Pinterest layout or the Imgur layout shown in the screenshot below. There's 2 columns and then each card has a variable height based on the height of the image it's showing.

What I'm having trouble with, is calculating the right width and height for sizeForItemAt, since I'm loading these images from URLs:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

I believe I can store the width and height of each image, but then how do I calculate the height I'll have to add from the little section beneath the picture, where there is more text. Currently I've built these cards in SwiftUI which is great for dynamically fitting the text, but I don't know how to get the size. Do I need to build these cards in Swift, or is there a way for me to get the additional height I have to add to the images height, for the aspect ratio to come out correctly?

Imgur Example

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.