Coder Social home page Coder Social logo

lisafiedler / accordianview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from milankamilya/accordianview

0.0 1.0 0.0 1.93 MB

Reusable AccordianView in swift. It will take less than 2 min to integrate it with your app.

License: MIT License

Swift 100.00%

accordianview's Introduction

AccordianView

Reusable AccordianView in swift. It will take less than 2 min to integrate it with your app.

Click on this GIF to have a full look on how the pull project looks like

YouTube Link

Installation

You need do it manually. Download and add the following file to your project.

MKAccordionView.swift

Usage

MKAccordionView follows delegation patterns like UITableView. So, if you have worked with UITableView, it is very easy for you to implement it. As you need to implement few delegate and datasource method of MKAccordionView.

// MARK: - Implemention of MKAccordionViewDelegate method
extension ViewController : MKAccordionViewDelegate {
    
    func accordionView(accordionView: MKAccordionView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 50
    }
    
    func accordionView(accordionView: MKAccordionView, heightForHeaderInSection section: Int) -> CGFloat {
        return 50
    }
    
    func accordionView(accordionView: MKAccordionView, viewForHeaderInSection section: Int, isSectionOpen sectionOpen: Bool) -> UIView? {
     
        var view : UIView! = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(accordionView.bounds), 50))

        // Customize section header view according to your need
        // "sectionOpen" will let you know section header is expended or collapsed. And you can change the 
        //  background color / image accordingly
        
        return view
        
    }
}

As we need to implement UITableviewDatasource in case of UITableView, here we need to do the same.

// MARK: - Implemention of MKAccordionViewDatasource method
extension ViewController : MKAccordionViewDatasource {
    
    func numberOfSectionsInAccordionView(accordionView: MKAccordionView) -> Int {
        return <# No of Sections #>
    }
    
    func accordionView(accordionView: MKAccordionView, numberOfRowsInSection section: Int) -> Int {
        return <# No of rows of a specific section #>
    }
    
    func accordionView(accordionView: MKAccordionView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell : UITableViewCell? = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: nil)
        
        // Customize cell according to your use
        
        return cell!
    }
}

When you are going to initialize the MKAccordionView, don’t forget to set delegate and datasource to self. Next add the object to view.

var accordionView : MKAccordionView = MKAccordionView(frame: CGRectMake(0, 22, CGRectGetWidth(view.bounds), CGRectGetHeight(view.bounds)))
accordionView.delegate = self
accordionView.dataSource = self
view.addSubview(accordionView)

Find it difficult to implement?

License

AccordianView is under MIT license so feel free to use it!

Author

Created by Milan Kamilya. Please feel free to drop an email if you have any question. [email protected] or tweet me @Milan_Kamilya

accordianview's People

Contributors

milankamilya avatar

Watchers

 avatar

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.