Swiftpack.co - Package - sbertix/CollectionUI

CollectionUI

GitHub tag (latest by date) GitHub

CollectionUI is a simple SwiftUI wrapper for UICollectionView.

Installation

Swift Package Manager (Xcode 11 and above)

  1. Select File/Swift Packages/Add Package Dependency… from the menu.
  2. Paste https://github.com/sbertix/CollectionUI.git.
  3. Follow the steps.

Usage

import SwiftUI
import CollectionUI
/// A `StringView` conforming to `UICollectionViewCellRepresentable`.
struct StringView : UICollectionViewCellRepresentable {
    /// The cell size.
    static var size: CGSize = .init(width: 100, height: 100)
    /// The item.
    var item: String
    
    /// Init.
    init(_ item: String) { self.item = item }
    /// The actual body.
    var body: some View { Text(item) }
}
/// A `View`.
struct ContentView : View {
    var body: some View {
        CollectionView<StringView>(.horizontal, // optional.
                                   data: ["A", "B", "C", "D"],
                                   id: \.hashValue,
                                   contentInset: .init(top: 0, left: 15, bottom: 0, right: 15), // optional.
                                   interitemSpacing: 10, // optional.
                                   lineSpacing: 10, // optional.
                                   showsIndicator: false /* optional. */) {
                                        // update the `UICollectionView`. optional.
                                        $0.alwaysBounceHorizontal = true    
             }
             .frame(height: 300)
    }
}

License

CollectionUI is licensed under the MIT license.
Check out LICENSE for more info.

Github

link
Stars: 2
Help us keep the lights on

Dependencies

Used By

Total: 0