Code Monkey home page Code Monkey logo

horizontalcardsview's Introduction

Cocoapods Platform Language License: MIT

HorizontalCardsView

Visual component realizes a horizontally scrollable list of cards.

Scrolling example

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

  1. Add UIView to storyboard and set Custom Class as HorizontalCardsView.

Storyboard

  1. Set you ViewController to conform HorizontalCardsDataSource and HorizontalCardsDelegateprotocols.
  2. Setup params viewsSource and delegate in viewDidLoad() for your HorizontalCardsView instance. Also, you should define params cardSpasing and insets. Height of cards is calculated as the height of HorizontalCardsView minus top and bottom insets. WIdth of cards is calculated as the width of HorizontalCardsView with cardWidthFactor or width of HorizontalCardsView minus 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.")
    }
    
    // ...
    
   }
  1. Views which you want to display in the scrollable list must be descendants of HorizontalCardView class. Override prepareForReuse() method, if you want to do some actions before views will be reused.

horizontalcardsview's People

Contributors

alexsmet avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

venky05

horizontalcardsview's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.