Easy way to create/reuse custom cells & headers with xib written in Swift
Easy way to setup custom cells with xib
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.1.0+ is required to build Reusable 1.0.0+.
To integrate Reusable into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'RSReusable'
end
Then, run the following command:
$ pod install
Make sure you name your cell's class and xib with the same names
class MyCell: UITableViewCell, Reusable {
import Reusable
//...
class MyCell: UITableViewCell, Reusable {
import Reusable
//...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeue(forIndexPath: indexPath) as MyCell
//setup cell ...
return cell
}
import Reusable
//...
class MySectionHeaderView: BaseTableSectionHeaderFooterView {
import Reusable
//...
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueHeaderFooterView() as MySectionHeaderView
//setup header ...
return header
}
import Reusable
//...
class MyCollectionCell: UICollectionViewCell, Reusable {
import Reusable
//...
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueCell(for: indexPath) as MyCollectionCell
//setup cell ...
return cell
}
import Reusable
//...
class CollectionHeaderView: UICollectionReusableView, Reusable {
import Reusable
//...
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueCell(for: indexPath) as CollectionHeaderView
//setup header ...
return header
}
Roman Sorochak - iOS developer. You may contact me via email: [email protected]
Reusable is released under the MIT license. See LICENSE for details.