Code Monkey home page Code Monkey logo

dgselfsizingcollectionviewcells's Introduction

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

screenshot

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

dgselfsizingcollectionviewcells's People

Contributors

danielgalasko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.