SwiftElegantDropdownMenu 0.1.6

SwiftElegantDropdownMenu 0.1.6

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2015
SPMSupports SPM

Maintained by Armin Likic.




  • By
  • Armin Likic

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Description

This component provides an easy, configurable dropdown menu with the ability to place it anywhere. It comes with a simple item selected callback and a variety of configurable options. This component is inspired by the BTNavigationDropdownMenu from PhamBaTho.

alt tag

Installation

SwiftElegantDropdownMenu is available through CocoaPods. To install it, simply add the following lines to your Podfile:

use_frameworks!
pod "SwiftElegantDropdownMenu"

Usage:

import SwiftElegantDropdownMenu

Example 1

Start by creating an array of dropdown elements:

let items = ["Zeus", "Hades", "Poseidon", "Chronos", "Aphrodite", "Artemis", "Hefestus"]

Create a new instance of SwiftElegantDropdownMenu:

let dropdownMenu = SwiftElegantDropdownMenu(title: items.first!, items: items)

Add the menu to your view as any other UIVIew:

self.view.addSubview(dropdownMenu)

Example 2

Create a new UIView storyboard element, assign the SwiftElegantDropdownMenu class to it, and create an outlet in your viewcontroller:

@IBOutlet weak var dropdownMenu: SwiftElegantDropdownMenu!

Assign the items and title properties to it:

self.dropdownMenu.items = items
self.dropdownMenu.title = items.first!

Example 3

You can handle the selection using a completion handler:

self.dropdownMenu.onItemSelect = {

(index, item) -> () in

// do something

}

You can handle what happens when the menu button is tapped:

self.dropdownMenu.onMenuButtonTapped = {

willOpen -> () in

// do something

}

Also, you have the freedom to customize the layout of the dropdown to match your needs:

...
self.dropdownMenu.configuration.titleFont = UIFont(name: "Arial", size: 22)!
self.dropdownMenu.configuration.cellTextColor = UIColor.redColor()
self.dropdownMenu.configuration.cellFont = UIFont(name: "Courier New", size: 18)!
...

Changelog

0.1.6 (11-28-2015)

  • Fixed vertical position issue for list.

0.1.5 (11-28-2015)

  • Fixed a crash issue.
  • Added an onMenuButtonTapped handler.

0.1.4 (11-28-2015)

  • Improved the dropdown to handle the case when there are multiple dropdowns present.
  • Added the ability to close the dropdown by tapping on the outter area.

0.1.3 (11-27-2015)

  • The issue that was causing the app to crash when multiple dropdowns have been added on the view has been resolved.

Author

Armin Likic, [email protected]

License

SwiftElegantDropdownMenu is available under the MIT license. See the LICENSE file for more info.