Render photos and captions beautifully using UIStackView
and UICollectionView
. Includes built-in support for multiple columns (via a property setter) and multi-line captions.
Compatible with iOS 9+ and the most recent Swift release (Swift 2.1).
StackViewPhotoCollage is implemented using UIStackView
, UICollectionView
, and a custom UICollectionViewLayout
subclass.
-
Clone this project
-
Drag the StackViewPhotoCollage/StackViewPhotoCollage folder into your project in XCode
-
Initialize a
UICollectionView
with theMultipleColumnLayout
layout -
Conform to
MultipleColumnLayoutDelegate
protocol on yourUICollectionView
data source (or another class) by implementing the following:protocol MultipleColumnLayoutDelegate: class { func collectionView(collectionView: UICollectionView, heightForPhotoAtIndexPath indexPath: NSIndexPath, withWidth width: CGFloat) -> CGFloat func collectionView(collectionView: UICollectionView, heightForAnnotationAtIndexPath indexPath: NSIndexPath, withWidth width: CGFloat) -> CGFloat }
-
Customize your
MultipleColumnLayout
layout instance as follows before adding it to yourUICollectionView
let multiColumnLayout = MultipleColumnLayout() multiColumnLayout.cellPadding = 5 multiColumnLayout.delegate = myDelegate // your UICollectionViewDataSource might be a good fit multiColumnLayout.numberOfColumns = 2 let myCollectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: multiColumnLayout)
Thank you Ray Wenderlich for the custom UICollectionView video tutorials, which were an inspiration for this project.
The MIT License (MIT)
Copyright (c) Giancarlo Daniele