Latest 2.0.1
Homepage https://github.com/gunnarhafdal/GHNavigationDropdownMenu
License MIT
Platforms ios 9.3
Authors

License: MIT
Language

Introduction:

The elegant dropdown menu, written in Swift, appears underneath navigation bar to display a list of related items when a user click on the navigation title. Forked from PhamBaTho/BTNavigationDropdownMenu because I needed Swift3 support and support for a subtitle in the menu items.

Usage:

Instantiating

Start by creating an Array that contains strings as elements of dropdown list:

let items = [
            GHDropdownItem(title: "Most Popular", subtitle: "from our users"),
            GHDropdownItem(title: "Latest", subtitle: ""),
            GHDropdownItem(title: "Trending", subtitle: "See what's happening"),
            GHDropdownItem(title: "Nearest", subtitle: "to you"),
            GHDropdownItem(title: "Top Picks", subtitle: "by our editors"),
        ]

Create a new instance of GHNavigationDropdownMenu:

let menuView = GHNavigationDropdownMenu(navigationController: self.navigationController, containerView: self.navigationController!.view, title: "Dropdown Menu", items: items)

or just simple like this:

let menuView = GHNavigationDropdownMenu(title: items[0], items: items)

By default, navigationController is the top most navigation controller and containerView is keyWindow.

(keyWindow is recommended for containerView because in this way, the black overlay can cover the whole screen. But in some cases, keyWindow doesn’t work properly, like using with side menu, (e.g. SWRevealViewController), the dropdown menu didn’t move along with their parent view controller or navigation controller. To resolve this issue, you can use self.navigationController!.view instead.)

Set title of navigation bar as menuView:

self.navigationItem.titleView = menuView

Call GHNavigationDropdownMenu closure to get the index of selected cell:

menuView.didSelectItemAtIndexHandler = {[weak self] (indexPath: Int) -> () in
            print("Did select item at index: (indexPath)")
            self.selectedCellLabel.text = items[indexPath]
}

Use menuView.show() or menuView.hide() if you want to show or hide dropdown menu manually.

Use menuView.toggle() to toogle dropdown menu shown/hide.

Use menuView.isShown (Boolean type) property to check showing state of dropdown menu.

Use menuView.updateItems(items: [AnyObject]) to update items in dropdown menu if needed.

Customization

Once you have assigned the items and frame for dropdown menu, you can custom the look and the feel of menu. You can override these properties for your favor:

cellHeight – The height of the cell. Default is 50

cellBackgroundColor – The color of the cell background. Default is whiteColor()

cellSeparatorColor – The color of the cell separator. Default is darkGrayColor()

cellTextLabelColor – The color of the text inside cell. Default is darkGrayColor()

cellTextLabelFont – The font of the text inside cell. Default is HelveticaNeue-Bold, size 17

navigationBarTitleFont – The font of the navigation bar title. Default is HelveticaNeue-Bold, size 17

cellTextLabelAlignment – The alignment of the text inside cell. Default is .Left

cellSelectionColor – The color of the cell when the cell is selected. Default is lightGrayColor()

checkMarkImage – The checkmark icon of the cell.

animationDuration – The animation duration of showing/hiding menu. Default is 0.5s

arrowImage – The arrow next to navigation title

arrowPadding – The padding between navigation title and arrow. Default is 15

maskBackgroundColor – The color of the mask layer. Default is blackColor()

maskBackgroundOpacity – The opacity of the mask layer. Default is 0.3

shouldKeepSelectedCellColor – The boolean value that decides if selected color of cell is visible when the menu is shown. Default is false

shouldChangeTitleText – The boolean value that decides if you want to change the title text when a cell is selected. Default is true

selectedCellTextLabelColor – The color of the selected cell text label. Default is darkGrayColor()

arrowTintColor – The tint color of the arrow. Default is whiteColor()

Requirement

  • iOS 9.3+
  • Xcode 9.0+, Swift 4.0+

Changelog

See the CHANGELOG for details

License

GHNavigationDropdownMenu is available under the MIT License. See the LICENSE for details.

Latest podspec

{
    "name": "GHNavigationDropdownMenu",
    "version": "2.0.1",
    "summary": "A dropdown menu",
    "description": "The dropdown menu, appears underneath navigation bar to display a list of related items when the user taps on the navigation title.",
    "homepage": "https://github.com/gunnarhafdal/GHNavigationDropdownMenu",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Gunnar Hafdal": "[email protected]"
    },
    "social_media_url": "http://twitter.com/GunnarHafdal",
    "platforms": {
        "ios": "9.3"
    },
    "source": {
        "git": "https://github.com/gunnarhafdal/GHNavigationDropdownMenu.git",
        "tag": "2.0.1"
    },
    "source_files": "Source/*.swift",
    "resources": "Source/*.bundle",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This