TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Apr 2016 |
SPMSupports SPM | ✗ |
Maintained by Jerry Yu.
A drop-down menu list as an alternative to UIPickerView.
Alternatively, you can add all source files in the “Source” folder to your project
Start by creating an array that contains strings as the elements of the JYDropDownMenu
let items: [String] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
Create a new instance of JYDropDownMenu
let dropDownMenu = JYDropDownMenu(frame: CGRect(x: 50, y: 50, width: 260, height: 40), title: "Choose An Item", items: items)
Implement the delegate
dropDownMenu.delegate = self
Add the JYDropDownMenu as a subview
.
self.view.addSubview(dropDownMenu)
Use delegate method to determine which item in the array was selected
func dropDownMenu(dropDownMenu: JYDropDownMenu, didSelectMenuItemAtIndexPathRow indexPathRow: Int)
UIView
onto your View
.Identity Inspector
, set custom class JYDropDownMenu
.outlet
to your source file, e.g. @IBOutlet weak var dropDownMenu: JYDropDownMenu!
Create an array that contains strings as the elements of the JYDropDownMenu
let items: [String] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
self.dropDownMenu = JYDropDownMenu(frame: self.dropDownMenu.frame, title: "Choose An Item", items: items)
Implement the delegate
self.dropDownMenu.delegate = self
Add the JYDropDownMenu as a subview
.
self.view.addSubview(self.dropDownMenu)
Use delegate method to determine which item in the array was selected
func dropDownMenu(dropDownMenu: JYDropDownMenu, didSelectMenuItemAtIndexPathRow indexPathRow: Int)
Once you have assigned the items and the frame of the JYDropDownMenu, you can customize the look of the menu. The following properties can be changed:
width
The width of the menu.
height
The height of the menu.
title
The title of the menu.
menuBackgroundColor
The background color of the menu title. Default is UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)
menuTitleTextAlignment
The text alignment of the menu title. Default is NSTextAlignment.Center
menuTitleFont
The font of the menu title. Default is UIFont.systemFontOfSize(17.0)
menuItemFont
The font of the menu items. Default is UIFont.systemFontOfSize(17.0)
menuRowHeight
The cell height of the menu items. Default is UITableViewAutomaticDimension
menuTitleColor
The font color of the menu title. Default is darkGrayColor()
menuItemColor
The font color of the menu items. Default is darkGrayColor()
JYDropDownMenu is available under the MIT License. See the LICENSE for details
Because this is the first time I attempted creating a CocoaPods library, I used, among other libraries, BTNavigationDropdownMenu and KSTokenView as inspiration. Kudos to the authors of those libraries.