Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delegate method for minimumColumnSpacing #208

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Source/CHTCollectionViewWaterfallLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private func > <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
@objc optional func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
columnCountFor section: Int) -> Int

@objc optional func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumColumnSpacingFor section: Int) -> CGFloat

@available(*, unavailable, renamed: "collectionView(_:layout:sizeForItemAt:)")
@objc optional func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
Expand Down Expand Up @@ -205,10 +209,13 @@ public class CHTCollectionViewWaterfallLayout: UICollectionViewLayout {
}

public func itemWidth(inSection section: Int) -> CGFloat {
let columnCount = self.columnCount(forSection: section)
let spaceColumCount = CGFloat(columnCount - 1)
let width = collectionViewContentWidth(ofSection: section)
return floor((width - (spaceColumCount * minimumColumnSpacing)) / CGFloat(columnCount))

let columnCount = self.columnCount(forSection: section)
let spaceColumnCount = CGFloat(columnCount - 1)
let columnSpacing = delegate?.collectionView?(collectionView!, layout: self, minimumColumnSpacingFor: section) ?? minimumColumnSpacing

return floor((width - (spaceColumnCount * columnSpacing)) / CGFloat(columnCount))
}

override public func prepare() {
Expand Down