The elegant yet functional dropdown menu, written in Swift, appears underneath the navigation bar to display a list of defined items when a user clicks on the navigation title.

Overview

alt tag

Pod Version License: MIT Language

Introduction

The elegant yet functional dropdown menu, written in Swift, appears underneath the navigation bar to display a list of defined items when a user clicks on the navigation title.

alt tag

Installation

CocoaPods

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

use_frameworks!
pod 'BTNavigationDropdownMenu'

Go ahead and import BTNavigationDropdownMenu into your own Swift files

import BTNavigationDropdownMenu

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate BTNavigationDropdownMenu into your Xcode project using Carthage, specify it in your Cartfile:

github "PhamBaTho/BTNavigationDropdownMenu" ~> 0.7

Run carthage update to build the framework and drag the built BTNavigationDropdownMenu.framework into your Xcode project.

Usage

Instantiate

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

let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"]

Create a new instance of BTNavigationDropdownMenu:

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

or like this:

let menuView = BTNavigationDropdownMenu(title: BTTitle.index(1), items: items)

BTTitle is an enum. We can set BTTitle.title(string) or BTTitle.index(Int) (Note: BTTitle.index is the index of defined items array).

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

(keyWindow is recommended for containerView so that the black overlay can cover the whole screen. In some cases, keyWindow doesn't work properly, like using with side menu (e.g. SWRevealViewController), the dropdown menu doesn't move along with the parent view or navigation controller. To workaround this issue, you can use self.navigationController!.view.)

Set title of navigation bar as menuView:

self.navigationItem.titleView = menuView

Call BTNavigationDropdownMenu 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]
}

menuView.show() or menuView.hide() to show or hide dropdown menu manually.

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

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

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

Customization

First, assign the items and frame for the dropdown menu. Then, customize the look and feel of the menu by overriding these properties:

Name Description Default value
navigationBarTitleFont Navigation bar title font System font, bold, size 17
cellHeight Cell height 50
arrowImage Arrow next to the navigation title Provided image
arrowPadding Padding between the navigation title and arrow 15
cellBackgroundColor Cell background color UIColor.white
cellSeparatorColor Cell separator color UIColor.darkGray
cellTextLabelColor Text color inside of the cell UIColor.darkGray
cellTextLabelFont Text font inside the cell System font, bold, size 17
cellTextLabelAlignment Text alignment inside of the cell NSTextAlignment.left
cellSelectionColor Selected color of the cell UIColor.lightGray
checkMarkImage Checkmark icon for the cell Provided image
animationDuration Animation duration for showing/hiding of the menu 0.3
maskBackgroundColor Mask layer color UIColor.black
maskBackgroundOpacity Opacity of the mask layer 0.3
menuTitleColor Title color displayed in the menu UIColor.lightGray
shouldKeepSelectedCellColor Selected cell color visibility when menu is shown false
shouldChangeTitleText Ability to change the selected title text true
selectedCellTextLabelColor Selected cell text label color UIColor.darkGray
arrowTintColor Tint color of the arrow UIColor.white

Requirement

  • iOS 9.0+

Changelog

See the CHANGELOG for details

License

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

Comments
  • Errors when using CocoaPods install as directed

    Errors when using CocoaPods install as directed

    This is similar to the issue reported [here].(https://github.com/PhamBaTho/BTNavigationDropdownMenu/issues/127)

    Our application, which is a mix of both Swift and Obj C code, has been using this library for quite a while. Our Podfile was using the following format:

    pod 'BTNavigationDropdownMenu', :git => 'https://github.com/PhamBaTho/BTNavigationDropdownMenu.git'

    With the release of Swift 4.2 this library was updated and we started seeing errors. We're trying to specify a specific version of this library to use, specifically 0.4.1, with the podfile format:

    pod 'BTNavigationDropdownMenu', '= 0.4.1'

    However, that is giving us the 87 errors referenced in the issue linked at the top of this post. Even when following the guide in the Installation instructions we're seeing errors.

    My questions are:

    1. Does anyone know the cause of these errors?
    2. What is the difference between specifying the pod using the standard pod 'BTNavigationDropdownMenu' format and having it point directly to the repo with the :git => flag?
    opened by cdunkel 12
  • let menuView = BTNavigationDropdownMenu(title: items.first!, items: items) get  error

    let menuView = BTNavigationDropdownMenu(title: items.first!, items: items) get error

    let menuView = BTNavigationDropdownMenu(title: items.first!, items: items) get error

    fatal error: unexpectedly found nil while unwrapping an Optional value
    
    opened by 85636682 12
  • Crash on init

    Crash on init

    I can't get the drop down menu to work, it keeps crashing as soon as it starts loading. It crashes at the point where it creates the frame in the "init" function. I am using Xcode 6.4 with iOS 8.

    Here's my code:

    import UIKit
    import CVCalendar
    import BTNavigationDropdownMenu
    
    class RosterViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate {
    
    @IBOutlet weak var menuButton:UIBarButtonItem!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var calendarView: CVCalendarView!
    @IBOutlet weak var menuView: CVCalendarMenuView!
    
    var menuViewNav: BTNavigationDropdownMenu!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        tableView.delegate = self
        tableView.dataSource = self
        tableView.tableFooterView = UIView()
    
        let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"]
        menuViewNav = BTNavigationDropdownMenu(title: "Hey", items: items)
        menuViewNav.didSelectItemAtIndexHandler = {(indexPath: Int) -> () in
            print("Did select item at index: \(indexPath)")
        }
        self.navigationItem.titleView = menuViewNav
    
        if self.revealViewController() != nil {
            menuButton.target = self.revealViewController()
            menuButton.action = "revealToggle:"
            self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }
    }
    
    opened by DennisDreissen 7
  • Error compiling project after install via CocoaPods

    Error compiling project after install via CocoaPods

    Hi,

    I have just installed BTNavigationDropdownMenu via CocoaPods. Now when I compile my project I get 83 errors related to BTNavigationDropdownMenu pod.

    Is there anything I should change?

    Demo project worked fine.

    opened by ebenj 6
  • DropdownMenu leaks memory

    DropdownMenu leaks memory

    Hi,

    i create a function which will create the DropdownMenu. Every time i run this function 2mb of ram will get lost.

    if i open a view like in you example close it an reopen it 5-10mb of ram are lost.

    hope you understand what i mean.

    i think it has something to do with "closures and strong reference cycle", but i didn´t find the error.

    Thanks.

    opened by Skyb0rg 6
  • All of a sudden... fatal error: unexpectedly found nil while unwrapping an Optional value

    All of a sudden... fatal error: unexpectedly found nil while unwrapping an Optional value

    Love this library. Been using it for a while now, but after upgrading cocoapods and reinstalling all the pods, I know am hitting a strange error. Nothing else has changed, but this is now the issue I'm seeing:

    cell.checkmarkIcon.hidden = (indexPath.row == selectedIndexPath) ? false : true

    Running XCode 7.3.1 and the latest BTNavigationDropdownMenu

    Any idea why this is happening? It could certainly be me, but I haven't been able to solve it for some time. Thanks!

    kane

    opened by kcfgl 5
  • Hide dropDownMenu when tapping outside its bounds

    Hide dropDownMenu when tapping outside its bounds

    Hello, is it possible to hide menu when a user taps outside its bounds? If not, could you give me a hint to which view should I add a tapGestureRecognizer?

    Thanks in advance

    opened by olbartek 5
  • leaky views - adds subview to window (in init!), never removes it

    leaky views - adds subview to window (in init!), never removes it

    If you have the menu on a secondary page that gets opened on nav, every time you visit it it adds a new child subview to window.

    "menuWrapper" is private, so you can't get access to it to force cleanup.

    enhancement help-wanted 
    opened by argh 4
  • How to close programatically?

    How to close programatically?

    @PhamBaTho Is there a way to close the menu programatically? When I press my rightBarButtonItem with the menu opens, it remains open, I would like to close it in my Action.

    Thanks!

    opened by allaire 4
  • Ability to programmatically select new index

    Ability to programmatically select new index

    I need a button inside my table view to trigger a new index be selected in the dropdown menu, therefore updating the text in the nav bar to match the newly selected index.

    opened by jordanhbuiltbyhq 3
  • Swift 3 error

    Swift 3 error

    Hi,

    I migrated to Swift 3 and I got the following error in BTConfiguration.swift: Cannot invoke initializer for type 'CGFloat' with an argument list of type '(CGFloat!)'

    screen shot 2016-09-14 at 2 40 46 pm

    I tried to solve it but all my tries didn't work.

    Any help?

    Thanks.

    opened by Maryom 3
  • App crashed when I changed arrowTintColor

    App crashed when I changed arrowTintColor

    I wanna change arrow tintClor like below. but crashed at self.menuArrow.tintColor = color

    error message is Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

    here is my code

    private var menuView: BTNavigationDropdownMenu!
    
     private func setupDropDownMenu() {
            let items = Artist.allCases.map { $0.rawValue }
            menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, containerView: self.navigationController!.view, title: items.first!, items: items)
            menuView.cellHeight = 45
            menuView.arrowPadding = 15
            menuView.animationDuration = 0.4
            menuView.cellBackgroundColor = .white
            menuView.cellTextLabelColor = .black
            menuView.cellTextLabelFont = UIFont.boldSystemFont(ofSize: 14)
            menuView.shouldKeepSelectedCellColor = true
            menuView.cellTextLabelAlignment = .left
            menuView.cellSelectionColor = .systemGray2
            menuView.checkMarkImage = nil
            //menuView.arrowTintColor = .white
            menuView.didSelectItemAtIndexHandler = { [weak self] index in
                self?.selectedArtist = Artist.allCases[index]
                self?.pagingViewController.reloadData()
            }
            self.navigationItem.titleView = menuView
        }
    

    please help me!

    opened by kou-yamamoto 0
  • Update to Swift 5 / Xcode 12

    Update to Swift 5 / Xcode 12

    Hi,

    the Framework in the current state has a compilation problem with Xcode 12, so I updated the project settings to the recommendations by Xcode and also let Xcode migrate to Swift 5, which needs no extra code adjustments.

    opened by Tobisaninfo 0
  • Issue when use

    Issue when use "setSelected"

    Hi I have a problem with a function "setSelected" I have a menu with 4 items. 4 Item is "Choose one for me" and the first is "Movie". When I tap on "Choose one for me" this call a function and in this function there is "menuDropDown.setSelected(index: 0)". I get the problem like the images attached. The arrow is not near "Movie"

    Schermata 2020-12-15 alle 18 26 35 Schermata 2020-12-15 alle 18 26 30
    opened by TillMoss 0
  • Added support for optional NSAttributedString, for cell text.

    Added support for optional NSAttributedString, for cell text.

    Hey, Tho. So, I wanted to use Apple's Symbols (as images) in my cells, so switched to using NSAttributedStrings with NSTextAttachments, for each UITableViewCell.

    In this PR, I added support for an optional NSAttributedString to set the cell's attributedText instead. items are now an array of type BTItem, which is a struct I created with a String and an optional NSAttributedString. If a NSAttributedString is set for an item, it will use that instead.

    I don't know if would be popular or not, since it is a breaking change with the previous array of Strings, for items, but otherwise it works the same. One would just pass in BTItem(string: "Text"), instead of "Text" for each element.

    -Stu

    opened by stucarney 0
Releases(0.7)
  • 0.7(Nov 16, 2020)

    Compatible with Swift 5 and Xcode 10.2+

    Fixed

    • Update deprecated index(of:) to firstIndex(of:) (#156)
    • Remove ImplicitlyUnwrappedOptional to be compatible with Swift 5.

    Improved

    • Update project configuration to be compatible with Swift 5 and Xcode 10.2+
    • Use system font as default value of navigationBarTitleFont.
    Source code(tar.gz)
    Source code(zip)
  • 0.6(Feb 19, 2019)

  • 0.5(Sep 18, 2018)

  • 0.4.1(Aug 1, 2016)

    • Merge PR #71: Now you can configure selectedCellTextLabelColor. arrowTintColor, navigationBarTitleFont
    • Merge PR #75: Now you can keep navigation title static when selecting items in dropdown menu
    • Change keepSelectedCellColor to shouldKeepSelectedCellColor
    • Fix a bug in updateItems() when updating menu view after HTTP request.
    Source code(tar.gz)
    Source code(zip)
  • 0.4(Jul 22, 2016)

    • Resolve issue #57 and #63. Now you can scroll to the last one when the list is longer than screen's height.
    • Resolve issue #62 (Alternate scope initialization). Now you can initialize menuView where title parameter doesn't need to be one of the items array.
    • Resolve issue #68. Now, you can use updateItems(items: [AnyObject]) to update items for the dropdown menu after it has been initialized.
    • Add containView as parameter when initializing menuView.
    Source code(tar.gz)
    Source code(zip)
  • 0.3(Apr 17, 2016)

Owner
Tho Pham
Tho Pham
Simple example of view that appears on tap button and dismiss with swipe gesture.

MenuWithSlide Simple SwiftUI example of how to show side menu with slide effect. On button press - appeares, on background tap or swipe right - dissmi

Evgeny 1 Nov 29, 2021
✨ Awesome Dropdown menu for iOS with Swift 5.0

The eligible dropdown menu for iOS, written in Swift 5, appears dropdown menu to display a view of related items when a user click on the dropdown menu. You can customize dropdown view whatever you like (e.g. UITableView, UICollectionView... etc)

Kyle Yi 1.3k Dec 26, 2022
UIKit drop down menu, simple yet flexible and written in Swift

DropDownMenuKit DropDownMenuKit is a custom UIKit control to show a menu attached to the navigation bar or toolbar. The menu appears with a sliding an

Quentin Mathé 258 Dec 27, 2022
A simple dropdown menu component for iPhone

AZDropdownMenu AZDropdownMenu is a simple dropdown menu component that supports Swift. Screenshots Code used in the screencast are included in the bun

Wu 194 Nov 14, 2022
🔻 Dropdown Menu for iOS with many customizable parameters to suit any needs

MKDropdownMenu Dropdown Menu for iOS with many customizable parameters to suit any needs. Inspired by UIPickerView. Installation CocoaPods MKDropdownM

Max Konovalov 531 Dec 26, 2022
JNDropDownMenu - Easy to use TableView style dropdown menu.

Overview Swift version of https://github.com/dopcn/DOPDropDownMenu Easy to use TableView style dropdown menu. Setup The only thing you

Javal Nanda 65 Jun 27, 2021
This is a simple Mac Catalyst example showcasing how to build a dropdown menu toolbar button using AppKit.

CatalystToolbarMenuButton This is a simple Mac Catalyst example showcasing how to build a dropdown menu toolbar button using AppKit. There are ways to

Steven Troughton-Smith 24 Dec 8, 2022
Control your display's brightness from the macOS menu bar. Simple and easy to use.

MonitorControl Lite Control your display's brightness from the macOS menu bar. Simple and easy to use. About MonitorControl Lite is a simplified versi

null 62 Dec 11, 2022
A Slide Menu, written in Swift, inspired by Slide Menu Material Design

Swift-Slide-Menu (Material Design Inspired) A Slide Menu, written in Swift 2, inspired by Navigation Drawer on Material Design (inspired by Google Mat

Boisney Philippe 90 Oct 17, 2020
adb-tools-mac is a macOS menu bar app written in SwiftUI for common adb tools.

adb-tools-mac is a macOS menu bar app written in SwiftUI for common adb tools.

Naman Dwivedi 930 Jan 2, 2023
Fantastic dropdown in Swift

Dropdowns ❤️ Support my app ❤️ Push Hero - pure Swift native macOS application to test push notifications Quick Access - Organise files in the Mac men

Khoa 307 Oct 17, 2022
⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion

CIRCLE MENU Simple, elegant UI menu with a circular layout and material design animations We specialize in the designing and coding of custom UI for M

Ramotion 3.4k Dec 29, 2022
Simple and Elegant Drop down menu for iOS 🔥💥

SwiftyMenu is simple yet powerfull drop down menu component for iOS. It allow you to have drop down menu that doesn't appear over your views, which gi

Karim Ebrahem 502 Nov 29, 2022
Swift-sidebar-menu-example - Create amazing sidebar menu with animation using swift

 SWIFT SIDEBAR MENU EXAMPLE In this project I create a awesome side bar menu fo

Paolo Prodossimo Lopes 4 Jul 25, 2022
Slide-Menu - A Simple Slide Menu With Swift

Slide Menu!! Весь интерфейс создан через код

Kirill 0 Jan 8, 2022
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

Hossam Ghareeb 84 Feb 4, 2022
EasyMenu - SwiftUI Menu but not only button (similar to the native Menu)

EasyMenu SwiftUI Menu but not only button (similar to the native Menu) You can c

null 10 Oct 7, 2022
Hamburger Menu Button - A hamburger menu button with full customization

Hamburger Menu Button A hamburger menu button with full customization. Inspired by VinhLe's idea on the Dribble How to use it You can config the looks

Toan Nguyen 114 Jun 12, 2022
a simple macOS menu bar application that shows you the lyrics of current playing spotify track.

lyricsify a simple macOS menu bar application that shows you the lyrics of current playing spotify track.

Krisna Pranav 4 Sep 16, 2021