Skip to content

Commit

Permalink
Fixed a bug that 1-pixel blank on the trailing appeared while with ze…
Browse files Browse the repository at this point in the history
…ro insets and more than 2 columns.
  • Loading branch information
Jinya committed Mar 28, 2022
1 parent 29bc53f commit ef76932
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ extension ViewController: UICollectionViewDataSource {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: WaterfallViewCell.reuseIdentifier, for: indexPath) as? WaterfallViewCell else {
fatalError()
}
let titles: [String] = ["Shanghai", "Chongqing", "New York", "San Francisco", "Tokyo", "Phuket", "Singapore", "Wuhan", "Shenzhen", "Los Angeles"]
let cities: [String] = ["Shanghai", "Chongqing", "New York", "San Francisco", "Tokyo", "Phuket", "Singapore", "Wuhan", "Shenzhen", "Los Angeles"]
let colors: [UIColor] = [.red, .magenta, .brown, .blue, .purple, .blue, .cyan, .gray, .green, .yellow, .purple]
cell.titleLabel.text = titles.randomElement()!
cell.titleLabel.text = cities.randomElement()!
cell.titleLabel.backgroundColor = colors.randomElement()!
return cell
}
Expand All @@ -88,6 +88,7 @@ extension ViewController: UICollectionViewDelegateWaterfallLayout {
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("did select item at \(indexPath.item)")
guard let selectedCell = collectionView.cellForItem(at: indexPath) as? WaterfallViewCell else { return }
print("Selected city is \(selectedCell.titleLabel.text ?? "None").")
}
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ A waterfall-like (Pinterest-style) layout for UICollectionView.

This library is a modified lightweight Swift version based on [`CHTCollectionViewWaterfallLayout`](https://github.com/chiahsien/CHTCollectionViewWaterfallLayout.git), very easy to integrated with your existing project just like using Apple official `UICollectionViewFlowLayout` and `UICollectionViewDelegateFlowLayout`.

## Requirements
iOS 9.0+

## Preview
![Preview](preview.gif)

## Requirements
iOS 9.0+

## Installation
#### Swift Package Manager (Recommended)

- Xcode > File > Swift Packages > Add Package Dependency
- Add `https://github.com/Jinya/WaterfallLayout.git`
- Select "Exact Version" (recommend using the latest exact version)

## Package Content
## Package content
Only contains:

- `UICollectionViewWaterfallLayout.swift`
- `UICollectionViewDelegateWaterfallLayout.swift`

and a mini example project.

## How to use
## Example codes
```swift
import UIKit
import WaterfallLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class UICollectionViewWaterfallLayout: UICollectionViewLayout {
let spaceColumnCount = CGFloat(columnCount - 1)
let columnSpacing = delegate?.collectionView?(collectionView!, layout: self, minimumColumnSpacingFor: section) ?? minimumColumnSpacing
let width = collectionViewContentWidth(ofSection: section)
return floor((width - (spaceColumnCount * columnSpacing)) / CGFloat(columnCount))
return (width - (spaceColumnCount * columnSpacing)) / CGFloat(columnCount)
}

override public func prepare() {
Expand Down

0 comments on commit ef76932

Please sign in to comment.