Giter Site home page Giter Site logo

asjdropdownmenu's Introduction

ASJDropDownMenu

iOS doesn't have a drop down menu by default. Developers are supposed to use the UIPickerView for similar functionality. Project design constraints may sometimes however necessitate the use of such a menu. This class is a subclass of UIView that has a UITableView embedded in it. It provides the functionality needed to show a drop down menu below any UIView and is customizable using various properties.

Installation

CocoaPods is the preferred way to install this library. Add this command to your Podfile:

pod 'ASJDropDownMenu'

Usage

Creating one is simple. The show method has a completion block which returns the selected item. You may hide the drop down there and then:

ASJDropDownMenu *dropDownMenu = [[ASJDropDownMenu alloc] initWithView:aView menuItems:anArrayOfASJDropDownMenuItems];
[dropDown showMenuWithCompletion:^(ASJDropDownMenu *dropDownMenu, ASJDropDownMenuItem *menuItem, NSUInteger index)
 {
   [dropDownMenu hideMenu];
 }];

Whichever view you provide during instantiation, the dropdown will appear exactly below it. The menu items need to be of type ASJDropDownMenuItems. Constructor methods are provided to generate them. Just attach an array of these to your drop down menu instance.

ASJDropDownMenuItem *itemWithTitle = [ASJDropDownMenuItem itemWithTitle:@"a title"];
ASJDropDownMenuItem *anotherItemWithTitle = [ASJDropDownMenuItem itemWithTitle:@"another title"];
anInstanceOfDropDownMenu.menuItems = @[itemWithTitle, anotherItemWithTitle];
ASJDropDownMenuItem *itemWithSubtitle = [ASJDropDownMenuItem itemWithTitle:@"a title" subtitle:@"a subtitle" image:anImage];
ASJDropDownMenuItem *anotherItemWithSubtitle = [ASJDropDownMenuItem itemWithTitle:@"another title" subtitle:@"another subtitle" image:anotherImage];
anInstanceOfDropDownMenu.menuItems = @[itemWithSubtitle, anotherItemWithSubitle];

alt tag

Customization

There are a few properties that you can use to customize the drop down menu:

@property (nullable, strong, nonatomic) UIColor *menuColor;

Sets the menu's background color.

@property (nullable, strong, nonatomic) UIColor *itemColor;

Sets the text color of the menu items.

@property (nullable, strong, nonatomic) UIFont *itemFont;

Sets the menu items' font.

@property (assign, nonatomic) CGFloat itemHeight;

Sets the height each menu item takes.

@property (assign, nonatomic) BOOL hidesOnSelection;

If set YES, the menu will hide when an item is tapped.

@property (assign, nonatomic) ASJDropDownMenuDirection direction;

You can show the menu below or above the specified view. Shows below by default.

@property (assign, nonatomic) ASJDropDownMenuScrollIndicatorStyle indicatorStyle;

You can set the scroll indicator styles default, black or white, which are the default UIScrollView indicator styles. If you want to set a custom color to the scroll indicator, you can look up ASJColoredScrollIndicators.

To-do

  • Animation to open and close.
  • Provision to add images.
  • Provision to close on item selection.
  • Option to open the drop down in up or down direction.
  • Move the screen to accomodate the drawer when keyboard shows.

License

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

asjdropdownmenu's People

Contributors

readmecritic avatar

Stargazers

anseee avatar MohsinAli avatar

Watchers

James Cloos avatar MohsinAli avatar  avatar

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.