WaterfallLayout
water-fall layout in iOS
Install / Use
/learn @sgr-ksmt/WaterfallLayoutREADME
WaterfallLayout
Waterfall layout in iOS

Features
- Can select flow/waterfall layout per section.
- Self-Sizing cell available

How to use
class ViewController: UIViewController {
@IBOutlet private weak var collectionView: UICollectionView! {
didSet {
let layout = WaterfallLayout()
layout.delegate = self
layout.sectionInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
layout.minimumLineSpacing = 8.0
layout.minimumInteritemSpacing = 8.0
layout.headerHeight = 50.0
collectionView.collectionViewLayout = layout
collectionView.register(...)
collectionView.dataSource = self
collectionView.delegate = self
}
}
}
extension ViewController: UICollectionDataSource {
...
}
extension ViewController: WaterfallLayoutDelegate {
func collectionViewLayout(for section: Int) -> WaterfallLayout.Layout {
switch section {
case 0: return .flow(column: 1) // single column flow layout
case 1: return .waterfall(column: 3) // three waterfall layout
default: return .flow(column: 2)
}
}
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(...)
}
}
Properties
public var minimumLineSpacing: CGFloat { get set }
public var minimumInteritemSpacing: CGFloat { get set }
public var sectionInset: UIEdgeInsets { get set }
public var headerHeight: CGFloat { get set }
public var headerInset: UIEdgeInsets { get set }
public var footerHeight: CGFloat { get set }
public var footerInset: UIEdgeInsets { get set }
public var estimatedItemSize: CGSize { get set }
Layout delegte
public protocol WaterfallLayoutDelegate: class {
// MARK: - Required
func collectionViewLayout(for section: Int) -> WaterfallLayout.Layout
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
// MARK: - Optional
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, minimumInteritemSpacingFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, minimumLineSpacingFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sectionInsetFor section: Int) -> UIEdgeInsets?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, headerHeightFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, headerInsetFor section: Int) -> UIEdgeInsets?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, footerHeightFor section: Int) -> CGFloat?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, footerInsetFor section: Int) -> UIEdgeInsets?
func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, estimatedSizeForItemAt indexPath: IndexPath) -> CGSize?
}
Requirements
- iOS 9.0+
- Xcode 9+
- Swift 4+
Installation
Carthage
- Add the following to your Cartfile:
github "sgr-ksmt/WaterfallLayout" ~> 0.1
- Run
carthage update - Add the framework as described. <br> Details: Carthage Readme
CocoaPods
WaterfallLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'WaterfallLayout', '~> 0.1'
and run pod install
Manually Install
Download all *.swift files and put your project.
Change log
Change log is here.
Communication
- 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.:muscle:
License
WaterfallLayout is under MIT license. See the LICENSE file for more info.
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate 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
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
