Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Collection View on iOS with auto layout in UICollectionViewCell to create cells with dynamic heights

License

Notifications You must be signed in to change notification settings

honghaoz/Dynamic-Collection-View-Cell-With-Auto-Layout-Demo

Repository files navigation

Dynamic-Collection-View-Cell-With-Auto-Layout-Demo

Demo for Collection View on iOS with auto layout in UICollectionViewCell to create cells with dynamic heights

Works on iOS7 and iOS8

Explanation

Cell is created in xib file, can be also created in code.

Cell is a basic cell with a title label and a content label. Title label has 1 line text and content label has multiple lines text.

There are totally 7 constraints for two labels:

For title label, there are top, leading, trailing spacing with superView. For content label, there are botton, leading, trailing spacing with superView. And there is a fixed vertical spacing between bottom of title label with top of content label

All of these 7 constraints have 1000 priority

For two labels, set their Content Hugging Priority and Content Compression Resistance Priority same as following pic:

Title label

Content label

Subclassing this UICollectionViewCell

In awakeFromNib(), for iOS7 remember to set

self.contentView.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidt

and in layoutSubviews()

add contentLabel.preferredMaxLayoutWidth = self.bounds.width - 2 * kLabelHorizontalInsets

Screen shots

About

Collection View on iOS with auto layout in UICollectionViewCell to create cells with dynamic heights

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages