DGSelfSizingCollectionViewCells
Simple implementation of self sizing UICollectionViewCells introduced in iOS 8.
Install / Use
/learn @danielgalasko/DGSelfSizingCollectionViewCellsREADME
DGSelfSizingCollectionViewCells
Simple implementation of self sizing UICollectionViewCells introduced in iOS 8. This is intended to assist with those coming from this Stack Overflow post. A picture says a thousand words

This project includes several examples of how self-sizing cells can be achieved. To enable self sizing cells you first need to set the estimatedItemSize property on UICollectionViewFlowLayout.
Then you need to decide on your approach for sizing your cells. You can either let auto layout do the work for you or you can override preferredLayoutAttributesFittingAttributes: and return an appropriate size.
When using Auto Layout make sure that your cells are properly constrained.
When using preferredLayoutAttributesFittingAttributes: you will probably need to cache the size you calculate to prevent the system from calling your implementation indefinitely.
If you modify the frame of the layoutAttributes object thats passed in it will most likely call your implementation again so make sure you calculate once and then just return the layoutAttributes object.
Be warned, if you are seeking to have your collection view look similar to UITableView you will need to do a lot more work.
Currently the default behaviour for flow layout is to let cells expand in a horizontal direction first.
This means if you want to fix the horizontal dimension you either need to force a width constraint on the cell as seen here or here
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
Languages
Security Score
Audited on Nov 3, 2025
