✨ Awesome Dropdown menu for iOS with Swift 5.0

Overview

YNDropDownMenu

Awesome Version Carthage Compatible Docs License: MIT Build Status Platform Swift 5.0

Updates

See CHANGELOG for details

Introduction

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)

demo demo2

Requirements

YNDropDownMenu written in Swift 5. Compatible with iOS 8.0+

Installation

Cocoapods

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

pod 'YNDropDownMenu'

Carthage

github "younatics/YNDropDownMenu"

Usage

import YNDropDownMenu

Init view with frame[CGRect], Views[UIView] and Titles[String]

let view = YNDropDownMenu(frame:frame, dropDownViews: dropDownViews, dropDownViewTitles: ["Apple", "Banana", "Kiwi", "Pear"])
self.addSubview(view)

done!

Inherit YNDropDownView (If you need)

class DropDownView: YNDropDownView {
   // override method to call open & close
    override func dropDownViewOpened() {
        print("dropDownViewOpened")
    }
    
    override func dropDownViewClosed() {
        print("dropDownViewClosed")
    }

    // Hide Menu
    self.hideMenu()

    // Change Menu Title At Index
    self.changeMenu(title: "Changed", at: 1)
    self.changeMenu(title: "Changed", status: .selected, at: 1)

    // Change View At Index 
    self.changeView(view: UIView(), at: 3)

    // Always Selected Menu
    self.alwaysSelected(at: 0)
    self.normalSelected(at: 0)
}

Customize

Show & Hide Menu

view.showAndHideMenu(at:1)

// When view is already opened
view.hideMenu()

Disable & Enable Menu

view.disabledMenu(at: 2)
view.enabledMenu(at: 3)

Always/Normal selected button label

view.alwaysSelected(at: 0)
view.normalSelected(at: 0)

Button Images with 3 situations (normal, selected, disabled)

view.setStatesImages(normalImages: [UIImage(named: "arrow_nor")], selectedImages: [UIImage(named: "arrow_sel")], disabledImages: [UIImage(named: "arrow_dim")])

Label color with 3 situations

view.setLabelColorWhen(normal: UIColor.black, selected: UIColor.blue, disabled: UIColor.gray)

Label font with 3 situations

view.setLabelFontWhen(normal: UIFont.systemFont(ofSize: 12), selected: UIFont.boldSystemFont(ofSize: 12), disabled: UIFont.systemFont(ofSize: 12))

BlurEffectView

// Enadbled or Disabled first (Default true)
view.backgroundBlurEnabled = false

// Use this line if you want to change UIBlurEffectStyle
view.blurEffectStyle = .light

// Or customize blurEffectView(UIView)
let backgroundView = UIView()
backgroundView.backgroundColor = UIColor.black
view.blurEffectView = backgroundView

// Animation end alpha
view.blurEffectViewAlpha = 0.7

Animation duration

view.showMenuDuration = 0.5
view.hideMenuDuration = 0.3

Animation velocity, damping

view.showMenuSpringVelocity = 0.5
view.showMenuSpringWithDamping = 0.8

view.hideMenuSpringVelocity = 0.9
view.hideMenuSpringWithDamping = 0.8

Change Menu Title At Index

view.changeMenu(title: "Changed", at: 1)
view.changeMenu(title: "Changed", status: .selected, at: 1)

Change View At Index

view.changeView(view: UIView(), at: 3)

Change Bottom Line

view.bottomLine.backgroundColor = UIColor.black
view.bottomLine.isHidden = false

Deprecated

extension YNDropDownMenu {
    @available(*, deprecated, message: "use init(frame: CGRect, dropDownViews: [UIView], dropDownViewTitles: [String]) instead")
    public init(frame: CGRect, YNDropDownViews: [YNDropDownView], dropDownViewTitles: [String])

    @available(*, deprecated, message: "use alwaysSelected(at index: Int) instead")
    open func alwaysSelectedAt(index: Int) {
        self.alwaysSelected(at: index)
    }
    
    @available(*, deprecated, message: "use disabledMenu(at index: Int) instead")
    open func disabledMenuAt(index: Int) {
        self.disabledMenu(at: index)
    }
    
    @available(*, deprecated, message: "use enabledMenu(at index: Int) instead")
    open func enabledMenuAt(index: Int) {
        self.enabledMenu(at: index)
    }

    @available(*, deprecated, message: "use showAndHideMenu(at index: Int) instead")
    open func showAndHideMenuAt(index: Int) {
        self.showAndHideMenu(at: index)
    }
}

extension YNDropDownView {
    @available(*, deprecated, message: "use changeMenu(title: String, at index: Int) instead")
    open func changeMenuTitleAt(index: Int, title: String) {
        self.delegate?.changeMenu(title: title, at: index)
    }
}

References

Please tell me or make pull request if you use this library in your application :)

@zigbang

MotionBook

Author

younatics Twitter

Thanks to

jegumhon

License

YNDropDownMenu is available under the MIT license. See the LICENSE file for more info.

Comments
  • Not working in my project

    Not working in my project

    It is showing "Unable to find a specification for YNDropDownMenu" while installing pod. My project's deployment target is 9.0. What is the issue?

    help wanted 
    opened by amitgajjar510 7
  • Error in Swift4-IOS11-Xcode9

    Error in Swift4-IOS11-Xcode9

    I have installed the most recent version of YNDropDownMenu however i got this error "/Users/x/Documents/IOS development/Kallos/Pods/YNDropDownMenu/YNDropDownMenu/YNDropDownMenu.swift:583:43: 'init(colorLiteralRed:green:blue:alpha:)' is unavailable: This initializer is only meant to be used by color literals" screen shot 2017-10-02 at 12 10 14

    enhancement 
    opened by siyavash4812 3
  • how can I change the top menu backgroundColor?

    how can I change the top menu backgroundColor?

    I need change the top menu backgroundColor to clear, you said use YNDropDownButton in issue15, but YNDropDownButton is not public, I can't use it by Carthage. I need this:

    opened by Pr-Chen 3
  • 스위프트 4.2로 업데이트 및 기능을 조금 추가해보았습니다.

    스위프트 4.2로 업데이트 및 기능을 조금 추가해보았습니다.

    안녕하세요! 멋진 오픈소스 만들어주셔서 감사합니다 :) YNDropDownMenu를 사용하면서 입맛에 맞게 조금 변경한점을 풀리퀘 보냅니다ㅎㅎㅎ (풀리퀘가 처음이라 이런식으로 하는게 맞는지 모르겠네요 ㅎㅎ...)

    변경사항은 아래와 같습니다!!

    1. 스위프트 4.2로 업데이트
    2. flatmap -> compactmap 으로 변경
    3. 드롭다운 arrow 이미지 대신 각각의 이미지 적용 기능 추가(setImageWhens)
    opened by vkcldhkd 1
  • Horizontal scrollview

    Horizontal scrollview

    Is there a way to have multiple titles on the YNDropDownMenu that can be scrolled horizontally? For example, instead of having only Apple, Banana, Kiwi and Pear, I could add 5 more and have them displayed by scrolling horizontally.

    opened by stelarelas 1
  • Where to change backgroundColor

    Where to change backgroundColor

    Hi,

    Very nice dropdown :-)

    Im trying to change the YNDropDownMenu backgroundColor to UIColor.white.withAlphaComponent(0.0), I can't find where to do this, any suggestions?

    Thanks Bennie

    opened by DeadLockGBG 1
  • Fix `setImageWhen(normal: UIImage?, selected: UIImage?, disabled: UIImage?)` didn't setup `buttonImagesArray`.

    Fix `setImageWhen(normal: UIImage?, selected: UIImage?, disabled: UIImage?)` didn't setup `buttonImagesArray`.

    remove setImageWhen(normal: UIImage?, selectedTintColor: UIColor, disabledTintColor: UIColor), setImageWhen(normal: UIImage?, selectedTintColorRGB: String, disabledTintColorRGB: String) functions; replace setImageWhen(normal: UIImage?, selected: UIImage?, disabled: UIImage?) with setStatesImages(normalImages: [UIImage?], selectedImages: [UIImage?], disabledImages: [UIImage?]); update Demo, README.

    opened by zhpengkun 0
  • DropDownViews could be hid

    DropDownViews could be hid

    I placed YNDropDownMenu inside a UIView, it seems to be hid when DropDownViews show up. Any way to solve this?

    Structures:

    • ViewController +- View +-- PageMenu:UIView +--- YNDropDownMenu

    Code:

    @IBOutlet weak var pageMenu: UIView!
    
    let menuView = YNDropDownMenu(frame: CGRect(x: 0, y: 0, width: self.pageMenu.frame.width, height: self.pageMenu.frame.height), dropDownViews: _customerDropViews, dropDownViewTitles: ["Menu1", "Menu2", "Menu3"])
      
    let FFA409 = UIColor.init(red: 255/255, green: 164/255, blue: 9/255, alpha: 1.0)
    menuView.setImageWhen(normal: UIImage(named: "arrow_nor"), selected: UIImage(named: "arrow_sel"), disabled: UIImage(named: "arrow_dim"))
    menuView.setImageWhen(normal: UIImage(named: "arrow_nor"), selectedTintColor: FFA409, disabledTintColor: FFA409)
    menuView.setImageWhens(normal: [UIImage(named: "arrow_nor"),UIImage(named: "arrow_nor"),UIImage(named: "arrow_nor")], selectedTintColorRGB: "FFA409", disabledTintColorRGB: "D3D3D3")
    menuView.setLabelColorWhen(normal: .gray, selected: menuFontColor, disabled: .black)
    menuView.setLabelFontWhen(normal: .systemFont(ofSize: 14), selected: .systemFont(ofSize: 14), disabled: .systemFont(ofSize: 14))
    menuView.bottomLine.isHidden = false
    menuView.bottomLine.backgroundColor = UIColor.init(red: 224/255, green: 224/255, blue: 224/255, alpha: 1)
    
    pageMenu.addSubview(menuView)
    
    opened by hchungi 0
  • Update to Swift4, can't call method in Objective-C

    Update to Swift4, can't call method in Objective-C

    In Swift4, a declaration within an NSObject-derived class will no longer infer @objc. https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md

    opened by Natai 0
  • don't need change dropDownView position

    don't need change dropDownView position

    When I used your component with clear background color I have noticed stange effect. dropDownView to bland with menu, but for second show menu this problem doesn't reproduce. I think you have refused change position, but In initViews() you forget this remove.

    I am making the pull request.

    opened by sofbix 0
  • add image masking function with color

    add image masking function with color

    라이브러리를 사용하다가 제가 필요한 기능이 몇개 수정해본것을 풀리퀘 넣어봅니다~

    수정된 사항은 1. 컬러마스킹 기능, 2. Hex 컬러 String값을 UIColor로 바꾸는 function 두가지를 setImageWhen 부분과 setLabelColorWhen 부분에 적용해보았습니다.

    혹시 문제되는 사항이 있으시다면 수정해주시거나 리뷰부탁드립니다. :) 감사합니다.

    opened by jiwoo-choi 0
  • Unable to set background color for menu.

    Unable to set background color for menu.

    Looking for setting the menu background color as clear Color. It is showing white color only. Tried with the demo project as well.

    view.setBackgroundColor(color: UIColor.clear)

    As an objective looking to be have one dropdown button on text field. On opening it will show search filter form within dropdown view.

    opened by ArvindPrakashJoshi 0
  • Implement in Table with an API

    Implement in Table with an API

    I am wanting to implement a table view, which is populated by an API, in the drop down. I added a table to the XIB file and created another XIB file for the table cell.

    Primary View Controller:

    class EcardSingleCategoryViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
    
    var ecards = Content
    let imageCache = NSCache<NSString,AnyObject>()
    
    @IBOutlet weak var ecardCollection: UICollectionView!
    
    var name = ""
    var id = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let ZBdropDownViews = Bundle.main.loadNibNamed("EcardCategories", owner: nil, options: nil) as? [UIView]
        let view = YNDropDownMenu(frame:CGRect(x: 0, y: 64, width: UIScreen.main.bounds.size.width, height: 64), dropDownViews: ZBdropDownViews!, dropDownViewTitles: ["Choose Category"])
    
       self.view.addSubview(view)
    }
    

    In the initViews() function, I get the following error ... for the "categoryTable.register( ... " code

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

    I'm not sure how I would go about calling the cell's XIB file and populate the data.

    Drop Down code:

    class EcardCategoriesMenu: YNDropDownView {
    
    @IBOutlet var categoryTable: UITableView!
    
    var categories = [CategoryItem]()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initViews()
    }
    
    func initViews() {
        
      //  categoryTable.register(UINib(nibName: "EcardCategoriesCell", bundle: nil), forCellReuseIdentifier: "EcardCategoriesCell")
        
        categoryTable.delegate = self
        categoryTable.dataSource = self
        
        DispatchQueue.main.async {
            let jsonUrlString = "https://*****/category"
            guard let url = URL(string: jsonUrlString) else { return }
    
            URLSession.shared.dataTask(with: url) { (data, response, err) in
                guard let data = data else { return }
                
                if err == nil {
                    do {
                        let decoder = JSONDecoder()
                        let ecardcategory = try decoder.decode(Category.self, from: data)
                        self.categories = ecardcategory.category
                        self.categories.sort(by: {$0.title < $1.title})
                    } catch let err {
                        print("Err", err)
                    }
                    
                    DispatchQueue.main.async {
                        print(self.categories.count)
                        self.categoryTable.reloadData()
                    }
                }
            }.resume()
        }
    }
    }
    extension EcardCategoriesMenu: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return categories.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "EcardCategoriesCell", for: indexPath) as? EcardCategoriesCell else { return UITableViewCell() }
        cell.categoryName.text = ("\(categories[indexPath.row].title)")
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let mainStoryboard:UIStoryboard = UIStoryboard(name: "Ecard", bundle: nil)
        let desVC = mainStoryboard.instantiateViewController(withIdentifier: "EcardSingleCategoryViewController") as! EcardSingleCategoryViewController
        desVC.id = String(categories[indexPath.row].id)
        let navigationController = UIApplication.shared.keyWindow?.rootViewController as! UINavigationController
        navigationController.pushViewController(desVC, animated: true)
    }
    }
    

    Cell Code:

    class EcardCategoriesCell: UITableViewCell {
        @IBOutlet weak var categoryName: UILabel!
    }
    

    Any help sorting through this would be great.

    opened by cbartellds 0
  • menu position is wrong in autolayout

    menu position is wrong in autolayout

    // filterView.snp.makeConstraints { (make) in // make.top.equalTo(64) // make.left.right.equalTo(view) // make.height.equalTo(38) // } I'm using SnapKit, the label of menu displays on top offset about half of height. pls check it.

    opened by fdddf 0
  • Support for orientation Change

    Support for orientation Change

    From what I can tell, by adding a YNDropDownMenu to my view, it creates three subviews for the items, the view to be toggled, and a background faded view.

    Everything works great if the user does not change their screen orientation, but if they do, the menu and it's three created views do not update their dimensions.

    I've tried manually adding constraints myself, but they only target one of the three views, and I have no way to access the other two views created to add constraints to them as well. Help?

    opened by ritteraf 0
Releases(3.1.0)
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
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
You can easily add awesome animated context menu to your app.

Context-Menu.iOS You can easily add awesome animated context menu to your app. Made in Check this [project on dribbble] (https://dribbble.com/shots/17

Yalantis 1.8k Nov 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
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
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
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
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
iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.

SlideMenuControllerSwift iOS Slide View based on iQON, Feedly, Google+, Ameba iPhone app. Installation CocoaPods pod 'SlideMenuControllerSwift' Carth

Yuji Hato 3.3k Dec 29, 2022
A simple side menu for iOS written in Swift.

ENSwiftSideMenu A lightweight flyover side menu component for iOS with the UIDynamic's bouncing animation, UIGestures and UIBlurEffect. Allows you to

Evgeny Nazarov 1.8k Dec 21, 2022
iOS Interactive Side Menu written in Swift.

Interactive Side Menu A customizable, interactive, auto expanding and collapsing side menu for iOS written in Swift. Here are some of the ways Interac

Handsome 706 Dec 15, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022
ExpandingMenu is menu button for iOS written in Swift.

ExpandingMenu ExpandingMenu is written in Swift. Requirements iOS 8.0+ Xcode 10.0+ Swift 3.x+ Installation CocoaPods You can install CocoaPods with th

null 454 Dec 7, 2022
A side menu controller written in Swift for iOS

Description SideMenuController is a custom container view controller written in Swift which will display the main content within a center panel and th

Teo 1.2k Dec 29, 2022