UICollectionView extension for showing beautiful grid!
If you execute sample, clone or download this repository and open demo project.
- call
adaptBeautifulGrid:gridLineSpace(:sectionInset)
when you want to update.
collectionView.adaptBeautifulGrid(4, gridLineSpace: 2.0)
// If you want to set sectionInset
let inset = UIEdgeInsetsMake(0.0, 4.0, 0.0, 4.0)
collectionView.adaptBeautifulGrid(4, gridLineSpace: 2.0, sectionInset: inset)
If collectionView's frame changed by Autolayout, call adaptBeautifulGrid:gridLineSpace(:sectionInset)
in viewDidLayoutSubviews
.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
view.layoutIfNeeded() // need to call before update collection view layout.
collectionView.adaptBeautifulGrid(4, gridLineSpace: 2.0)
}
If Device'rotation changed, call adaptBeautifulGrid:gridLineSpace(:sectionInset)
in viewDidLayoutSubviews
.
e.g. : Portrait→4, Landscape→6
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
view.layoutIfNeeded() // need to call before update collection view layout.
let isLandscape = UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)
let perRow = 4 + (isLandscape ? 2 : 0)
collectionView.adaptBeautifulGrid(perRow, gridLineSpace: 2.0)
}
- iOS 8.0+
- Xcode 7.0+(Swift 2+)
- Add the following to your Cartfile:
github "sgr-ksmt/BeautifulGridLayout"
- Run
carthage update
- Add the framework as described.
Details: Carthage Readme
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request. :)