A simple dropdown menu component for iPhone
AZDropdownMenu is a simple dropdown menu component that supports Swift.
Code used in the screencast are included in the bundled sample project.
To run the demo project, clone the repo with
git clone https://github.com/Azuritul/AZDropdownMenu.git, and run
pod installfrom the Example directory first.
AZDropdownMenu is available through CocoaPods. To install it, simply add the following line to your Podfile:
use_frameworks! pod 'AZDropdownMenu'
Use version 1.1.2 if you don't need Swift 4 support.
Declare an array of texts that are served as the item in the menu.
swift let titles = ["Action 1", "Action 2", "Action 3"]Then pass the array to the initializer
swift let menu = AZDropdownMenu(titles: titles)
Set up so that the
UIBarButtonItemis asso
ated with a function that shows the menu
let button = UIBarButtonItem(image: UIImage(named: "menu_image"), style: .Plain, target: self, action: "showDropdown") navigationItem.leftBarButtonItem = menuButton
Calling
public func showMenuFromView(view:UIView)can then show the menu.
swift func showDropdown() { if (self.menu?.isDescendantOfView(self.view) == true) { self.menu?.hideMenu() } else { self.menu?.showMenuFromView(self.view) } }
The handler
public var cellTapHandler : ((indexPath:NSIndexPath) -> Void)?would be called when menu item is tapped. So place code in here to do whatever you want. For example
menu.cellTapHandler = { [weak self] (indexPath: NSIndexPath) -> Void in self?.navigationController?.pushViewController(controller, animated:true) }
Pass in a AZDropdownMenuItemData in the initializer:
public init(dataSource:[AZDropdownMenuItemData])and you are good to go.
Take a look at the sample project in this repository to get more usage of the library.
Currently AZDropdownMenu can be customized with the following properties. More will come in the future.
itemHeightRow height of the menu item. Default is 44.
itemColorThe background color of the menu item. Default is white.
itemFontColorThe text color of the menu item. Default is black.
itemFontSizeFont size of the menu item. Default is 14.0
itemFontFont used in the menu. Default is 'Helvetica'
itemAlignmentThe alignment of the menu item. Default is left-aligned.
itemSelectionColorThe background color of the menu item while it is tapped. Default is gray.
overlayAlphaThe transparency for the background overlay. Default is 0.5
overlayColorColor for the background overlay. Default is black.
menuSeparatorStyleThe separator of the menu. Default is single line.
menuSeparatorColorThe color of the separator. Default is light gray.
itemImagePositionThe position of image in the menu. Can be positioned before or after the text. Default is
.Prefix.
shouldDismissMenuOnDragIf set to true, menu would be dismissed on drag. Default value is
false.
1.1.3
1.1.2
1.1.1
1.1.0
shouldDismissMenuOnDragoption, menu would be dismissed on drag if this option is enabled
UITableView.
1.0.0
itemImagePositionoption, now can configure the icon position.
0.6.1
0.6.0
menuSeparatorColor,
itemFont
0.5.3
Chris Wu (Azuritul), [email protected]
AZDropdownMenu is available under the MIT license. See the LICENSE file for more info.