JNDropDownMenu - Easy to use TableView style dropdown menu.

Related tags

Menu JNDropDownMenu
Overview

JNDropDownMenu

CI Status Version License Platform Twitter: @javalnanda

Overview

Swift version of https://github.com/dopcn/DOPDropDownMenu

Easy to use TableView style dropdown menu.

image

Setup

The only thing you need to do is import JNDropDownMenu, create an instance and add it to your View and conform to its datasource and delegate.

import JNDropDownMenu
// pass origin of menu, height - this will be height of collapsed menu not the expanded menu, width - it is optional, pass custom width or pass nil to utilize screen width
let menu = JNDropDownMenu(origin: CGPoint(x: 0, y: 64), height: 40, width: self.view.frame.size.width)
        menu.datasource = self
        menu.delegate = self
        self.view.addSubview(menu)

Just implement datasource and delegate same as that of Tableview

extension ViewController: JNDropDownMenuDelegate, JNDropDownMenuDataSource {
    func numberOfColumns(in menu: JNDropDownMenu) -> NSInteger {
        return 2
    }
    
    func numberOfRows(in column: NSInteger, for forMenu: JNDropDownMenu) -> Int {
        switch column {
        case 0:
            return columnOneArray.count
        case 1:
            return columnTwoArray.count
        default:
            return 0
        }
    }
    
    func titleForRow(at indexPath: JNIndexPath, for forMenu: JNDropDownMenu) -> String {
        switch indexPath.column {
        case 0:
            return columnOneArray[indexPath.row]
        case 1:
            return columnTwoArray[indexPath.row]
            
        default:
            return ""
        }
    }
    
    func didSelectRow(at indexPath: JNIndexPath, for forMenu: JNDropDownMenu) {
        var str = ""
        switch indexPath.column {
        case 0:
            str = columnOneArray[indexPath.row]
            break
        case 1:
            str = columnTwoArray[indexPath.row]
            break
        default:
            str = ""
        }
        label.text = str + " selected"
    }
}

Customization

There are very minimal customization available currently. You can alter color and font before setting menu datasource as follow:

    let menu = JNDropDownMenu(origin: CGPoint(x: 0, y: 64), height: 40, width: self.view.frame.size.width)
    //customize
    menu.textColor = UIColor.red
    menu.cellBgColor = UIColor.green
    menu.arrowColor = UIColor.black
    menu.cellSelectionColor = UIColor.white
    menu.textFont = UIFont.boldSystemFont(ofSize: 15.0)
    menu.updateColumnTitleOnSelection = false // Override titleFor(column: Int, menu: JNDropDownMenu) if you are setting this to false
    menu.arrowPostion = .Left

    menu.datasource = self
    menu.delegate = self
    self.view.addSubview(menu)
Find the above displayed examples in the Example folder.

Installation

CocoaPods

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

pod "JNDropDownMenu"

Change Log

V 0.1.4

  • added support to pass custom width for menu
  • expand menu now utilize entire screen height instead of 5 rows.

V 0.1.5

  • added support to provide custom column title and disable change of title on row selection.

Set updateColumnTitleOnSelection flag to false. This will disable change of column title on row selection. Note: This will also disable highlight of last selected row item.

 menu.updateColumnTitleOnSelection = false

Override following function of JNDropDownMenuDataSource to provide custom title for column

func titleFor(column: Int, menu: JNDropDownMenu) -> String {
        return "Column \(column)"
    }

Note: If you don't override this, by default it will pick first object of column array as a column title and by default it will update the title of column on row selection.

V 0.1.6

  • added support to define arrow position to left or right. Default is right.

Usage

menu.arrowPostion = .Left

Suggestions or feedback?

Feel free to create a pull request, open an issue or find me on Twitter.

Comments
  • DidSelectRow delegate not works

    DidSelectRow delegate not works

    I'm using this library with 3 columns, but can't catch did select row delegate. func didSelectRow(at indexPath: JNIndexPath, for forMenu: JNDropDownMenu) { print("selected some") var str = "" switch indexPath.column { case 0: str = cousins[indexPath.row] break case 1: str = categories[indexPath.row] break case 2: str = regions[indexPath.row] break default: str = "" } print(str + " selected") }

    invalid 
    opened by kerimovscreations 11
  • Enhancement request: set column title

    Enhancement request: set column title

    Hi - I have a use case where the drop down is a list of filter criteria for a list - each row can be selected or deselected by clicking on it and it has a tick or cross to indicate if it is selected (example below). I can update the row text dynamically and this works OK, but the column title is automatically set to the last selected item when I would like to be able to set it manually - with something like a function of JNDropDownMenu: func setTitle(_ title : String, forColumn: NSInteger) If not called it would default to the existing behaviour, but if present would set the column title to the specified value irrespective of the last item selected.

    Let me know what you think - Thanks, Phil

    screen shot 2017-05-09 at 22 37 57 enhancement 
    opened by FleetPhil 6
  • Split view controller master not working?

    Split view controller master not working?

    Hi - I'm trying to get the drop down menu working on the master list of a split view controller and it looks like there is an incompatibility? If I clone the code from the example and use it on a UItableview controller in the master list of a split view controller only one of the menus is shown, and on the right hand side of the view, if I rotate so only the master list is shown it is displayed correctly.

    Is this a known incompatibility? Thanks Phil

    enhancement 
    opened by FleetPhil 4
  • Limit of 5 to number of menu rows?

    Limit of 5 to number of menu rows?

    Is there a limit of 5 to the number of menu rows? If you add add more rows to the source array in the example (columnOneArray) they don't show on the drop-down menu? Thanks

    opened by FleetPhil 3
  • Method conflict with SpreadsheetView

    Method conflict with SpreadsheetView

    There are some methods conflict with SpreadsheetView (I use this to display data and your plugin to choose which dataset to display). How can I use both? numberOfColumns is an example.

    opened by tuononh 1
  • Customize position of title and indicator

    Customize position of title and indicator

    First of all thanks for the great pod. Did you thought about adding a way to specify the position of the titleLayer and the indicator? In my case I want the title to be on the left side of the menu and the indicator on the other side.

    enhancement 
    opened by MaciDE 1
  • Example doesn't work

    Example doesn't work

    JNDropDownMenu/Example/JNDropDownSample/ViewController.swift:23:20: Cannot invoke initializer for type 'JNDropDownMenu' with an argument list of type '(origin: CGPoint, height: Int, width: CGFloat)'

    opened by Gargo 1
  • compile errors under swift 4.1 when included with pod

    compile errors under swift 4.1 when included with pod

    if the swift version is 4.1, when included this with pod,it will need to change func menuTapped to @objc func menuTapped,
    change func backgroundTapped to @objc func backgroundTapped, change NSFontAttributeName to NSAttributedStringKey.font in func calculateTitleSizeWith

    opened by junlianglincanada 0
  • func titleForRow doesn't support tags of tableview

    func titleForRow doesn't support tags of tableview

    I use a controller to control two tableviews,and they both get a JNDropDownMenu. In this case,I use the tag of tableviews to distinguish them in JNDropDownMenuDataSource. However,all functions support tags of tableview except func titleForRow.

    opened by WhatTheNathan 0
  • Can it support double column dropdown pattern?

    Can it support double column dropdown pattern?

    Hi,

    Thanks for creating such a good repo for Swift. I have a simple question that can JNDropDownMenu support double column dropdown pattern like what is done in https://github.com/12207480/DOPDropDownMenu-Enhanced ?

    Thanks!

    enhancement question 
    opened by imadeit 1
Releases(0.1.6)
Owner
Javal Nanda
Javal Nanda
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.

Introduction The elegant yet functional dropdown menu, written in Swift, appears underneath the navigation bar to display a list of defined items when

Tho Pham 2.7k Dec 28, 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
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
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
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
An elegant dropdown for iOS written in Swift.

UIDropDown An elegant dropdown for iOS written in Swift. Overview UIDropDown allows you to pick an option in a table just like dropdowns in web. It co

Isaac Gongora 87 Mar 30, 2022
Library provides easy to implement variation of Android (Material Design) Floating Action Button for iOS. You can use it as your app small side menu. 🌶

RHSideButtons ?? Library provides easy to implement variation of Android (Material Design) Floating Action Button for iOS. You can use it as your app

Robert Herdzik 166 Nov 14, 2022
An easy way to use `canPerformAction` for context menu in SwiftUI.

Use canPerformAction for TextField/Editor in SwiftUI You know how a TextField displays a set of context menu? It doesn't matter if it's UIKit or Swift

StuFF mc 5 Dec 18, 2021
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
Easy-to-use action menu

About Navigate Features Installation Usage Delegate Features Highly customizable support dark/light theme corner radius blured background width (iPad)

Vlad Karlugin 4 Jan 6, 2023
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English 简体中文 What's a better way to know what PopMenu o

Cali Castle 1.5k Dec 30, 2022
iOS 7/8 style side menu with parallax effect.

RESideMenu iOS 7/8 style side menu with parallax effect inspired by Dribbble shots (first and second). Since version 4.0 you can add menu view control

Roman Efimov 7.2k Dec 28, 2022
A simple circle style menu.

Support CocoaPods. New at 2019.02.25 Use @property (nonatomic, assign) BOOL isOpened; can open or close RoundMenu. use -(void)setButtonEnable:(BOOL)en

zsy78191 383 Dec 21, 2022
Menu controller with expandable item groups, custom position and appearance animation written with Swift. Similar to ActionSheet style of UIAlertController.

Easy to implement controller with expanding menu items. Design is very similar to iOS native ActionSheet presentation style of a UIAlertController. As

Anatoliy Voropay 22 Dec 27, 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
Slide-Menu - A Simple Slide Menu With Swift

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

Kirill 0 Jan 8, 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
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