nicolasFernandez / AccordionMenuSwift

The best way of implement an accordion menu using an UITableView in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accordion Custom Image

Build Status Pods Version Swift Version License Type


An accordion/dropdown menu to integrate in your projects.

Main Features
πŸ“± Compatible with iPhone / iPad
πŸ”¨ Fully customizable cells
πŸš’ Supports device rotation
πŸ”₯ Written completely in Swift

Requirements πŸ’₯

  • iOS 8.0+
  • Xcode 8.0+

Installation

CocoaPods

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 Alamofire 4.0.0+.

To integrate AccordionMenuSwift 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 'AccordionMenuSwift', '~> 1.2.6'
end

Then, run the following command:

$ pod install

Usage ✨

After import the framework it's neccessary to inherit from the class AccordionTableViewController and set it's data source the total of items from the data source and if you like if several cells is expanded or only one like in the following example:

import UIKit
import AccordionMenuSwift

class AccordionViewController: AccordionTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let item1 = Parent(state: .collapsed, childs: ["SubItem 1", "SubItem 2", "SubItem 3"], title: "Item 1")
        let item2 = Parent(state: .collapsed, childs: ["SubItem 1", "SubItem 2"], title: "Item 2")
        let item3 = Parent(state: .collapsed, childs: ["SubItem 1", "SubItem 2", "SubItem 3"], title: "Item 3")
        let item4 = Parent(state: .collapsed, childs: ["SubItem 1", "SubItem 2"], title: "Item 4")
        let item5 = Parent(state: .collapsed, childs: [], title: "Item 5") // No childs for this cell

        dataSource = [item1, item2, item3, item4, item5]
        numberOfCellsExpanded = .several
        total = dataSource.count
    }
}

In the above example the AccordionViewController in Interface Builder it's an UITableViewController.

Afterwards it's necessary to define two cells in the UITableView with the identifiers "ParentCell" and "ChildCell".

You can see the Example project for more information in how to integrate it.

ToDo

  • Add Carthage support.
  • Add suport to be notified when cell is tapped using closures.
  • Add support for multiple levels
  • Improve the integration with functional programming
  • Add unit tests for the library

Feedback

I've found a bug, or have a feature request

Please raise a GitHub issue. 😱

Interested in contributing?

Great! Please launch a pull request. πŸ‘


License:

The MIT License. See the LICENSE file for more infomation.

About

The best way of implement an accordion menu using an UITableView in Swift

License:MIT License


Languages

Language:Swift 44.7%Language:Ruby 20.0%Language:Shell 17.0%Language:HTML 15.9%Language:Objective-C 2.4%