HorizontalCardsView
Visual component realizes a horizontally scrollable list of cards.
Installation
CocoaPods
CocoaPods is the preffered way to add HorizontalCardsView to your project.
Just add following line to your Podfile
pod 'HorizontalCardsView'
Then run a pod install inside your terminal.
After that you can include HorizontalCardsView wherever you need it with
import HorizontalCardsView
Usage
- Add
UIViewto storyboard and setCustom ClassasHorizontalCardsView.
- Set you
ViewControllerto conformHorizontalCardsDataSourceandHorizontalCardsDelegateprotocols. - Setup params
viewsSourceanddelegateinviewDidLoad()for yourHorizontalCardsViewinstance. Also, you should define paramscardSpasingandinsets. Height of cards is calculated as the height ofHorizontalCardsViewminus top and bottom insets. WIdth of cards is calculated as the width ofHorizontalCardsViewwithcardWidthFactoror width ofHorizontalCardsViewminus left and right insets if the component contains a single card.
class ViewController: UIViewController, HorizontalCardsDataSource, HorizontalCardsDelegate {
@IBOutlet weak var horizontalCardsView: HorizontalCardsView!
// ...
override func viewDidLoad() {
horizontalCardsView.dataSource = self
horizontalCardsView.delegate = self
horizontalCardsView.cellSpacing = 15
horizontalCardsView.inset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
}
// ...
func horizontalCardsViewNumberOfItems(_ collectionView: HorizontalCardsView) -> Int {
return 5
}
func horizontalCardsView(_: HorizontalCardsView, viewForIndex index: Int) -> HorizontalCardView {
let bundle = Bundle(for: SampleView.self)
let view = bundle.loadNibNamed("SampleView", owner: self, options: nil)?.first
return view
}
func horizontalCardsView(_: HorizontalCardsView, didSelectItemAtIndex index: Int) {
print("A view with index \(index) was selected.")
}
// ...
}- Views which you want to display in the scrollable list must be descendants of
HorizontalCardViewclass. OverrideprepareForReuse()method, if you want to do some actions before views will be reused.

