AliSoftware / Reusable

A Swift mixin for reusing views easily and in a type-safe way (UITableViewCells, UICollectionViewCells, custom UIViews, ViewControllers, Storyboards…)
MIT License
3k stars 239 forks source link

Added support for UICollectionViewLayout Decoration View #119

Open pookjw opened 2 years ago

pookjw commented 2 years ago

Old Style

import UIKit

class MyCollectionViewLayout: UICollectionViewCompositionalLayout {
    required init?(coder: NSCoder) {
        super.init { (section, layoutEnvironment) -> NSCollectionLayoutSection? in
            /* code */
        }

        let nib: UINib = .init(nibName: String(describing: MyCollectionReusableView.self), bundle: .main)
        register(nib, forDecorationViewOfKind: String(describing: MyCollectionReusableView.self))
    }
}

New Style

import UIKit
import Reusable

class MyCollectionViewLayout: UICollectionViewCompositionalLayout {
    required init?(coder: NSCoder) {
        super.init { (section, layoutEnvironment) -> NSCollectionLayoutSection? in
            /* code */
        }

        register(decorationViewType: MyCollectionReusableView.self)
    }
}