GithubHelp home page GithubHelp logo

m3g0byt3 / dsdmenu Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 921 KB

A dead-simpe, UIKit-based dropdown menu, written in Swift

License: MIT License

Swift 95.76% Ruby 4.24%
swift uikit menu dropdown-menus drop-down dropdownmenu dropdown-menu dropdownbutton

dsdmenu's Introduction

DSDMenu

CI Status Version License Platform iOS GitHub issues

โ€” Dead Simpe Dropdown Menu

A simple drop-down menu written in Swift.

Example

Features


  • Automatically update menu button content based on selected cell
  • Use delegate or configuration closure to setup menu
  • Use default or custom menu cells (with and without NIBs)
  • Create menu programmatically or in the Interface Builder

Requirements


  • iOS 9.0+
  • Xcode 9.0+
  • Swift 4.0+

Example


To run the example project, clone the repo, and run pod install from the Example directory first.

Installation


DSDMenu is available via CocoaPods.

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. You can install it with the following command:

$ sudo gem install cocoapods

To integrate DSDMenu, simply add the following line to your Podfile:

pod 'DSDMenu'

Then, run the following command:

pod install

Usage


Initialization:

  1. Programmatically:

    Use convenience initializer:

    init(title: String, frame: CGRect = CGRect.zero)
  2. Using Interface Builder

    Place a UIButton object on the storyboard and change custom class as pictured below:

    Interface Builder setup

Customize menu behaviour:

DSDMenu can be customized and controlled using two ways (mutually exclusive!):

  1. Using delegete (old-way):

    Confrom to DropDownDelegate protocol and assign delegate:

    1. Programmatically:

      menu.delegate = self
    2. Using Interface Builder:

      Interface Builder delegate

  2. Using configuration closure (new-way):

    Instantiate menu instance, then pass closure with a DropDownMenuConfigurator instance inside, configured within this closure, to the configure(using: (DropDownMenuConfigurator) -> Void) method:

    menu.configure { configurator in
      configurator.cellClass(DropDownCell.self)
                  .numberOfItems(10)
                  .updateThumbnailOnSelection(true)
                  .didSelectItem { index in print(index) }
                  .willDisplayCell { (cell, index) in print(cell, index) }
    }

API reference:


Delegate method Configuration method equivalent Description
numberOfItems(in:) numberOfItems(_:) Asks the delegate for the number of items in menu
cellClass(for:) cellClass(_:) Asks the delegate for the cell class used in menu
dropDownMenu(_:didSelectItemAt:) didSelectItem(_:) Tells the delegate that the item in the menu was tapped
dropDownMenu(_:willDisplay:forRowAt:) willDisplayCell(_:) Tells the delegate that the cell in the menu is about to be displayed
updateThumbnailOnSelection(in:) updateThumbnailOnSelection(_:) Asks the delegate whether the menu should update thumbnail image automatically on selection

TODO Section


  • Configure using closure instead of delegate
  • Auto-update view based on selected cell's content
  • Setup constraints in updateConstraints() (see also)
  • Setup Pod
  • Complete README
  • Correct handling of orientation changes when updateThumbnailOnSelection = true
  • Use POP for cells instead subclassing (if possible?)
  • Allow to customize menu's appearance (shadows, colors, etc)
  • Unit and UI tests
  • Rx extension

Contributing


Contributing is always welcomed, just follow these steps:

  1. Fork
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

That's it!

Author


m3g0byt3

License


DSDMenu is released under an MIT license. See LICENSE for more information.

dsdmenu's People

Contributors

m3g0byt3 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

carabina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.