Giter VIP home page Giter VIP logo

btnavigationdropdownmenu's Introduction

Support Xcode 10 and Swift 4.2 now.


alt tag

Pod Version License: MIT Language

Introduction

This elegant Swift dropdown menu appears underneath the navigation bar to display a list of related 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.5

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:

cellHeight - Cell height Default is 50

cellBackgroundColor - Cell background color Default is whiteColor()

cellSeparatorColor - Cell separator color Default is darkGrayColor()

cellTextLabelColor - Text color inside of the cell Default is darkGrayColor()

cellTextLabelFont - Font inside the cell Default is HelveticaNeue-Bold, size 17

navigationBarTitleFont - Navigation bar title font Default is HelveticaNeue-Bold, size 17

cellTextLabelAlignment - Text alignment inside of the cell Default is .Left

cellSelectionColor - Selected color of the cell Default is lightGrayColor()

checkMarkImage - Checkmark icon for the cell.

animationDuration - Animation duration for showing/hiding of the menu Default is 0.5s

arrowImage - Arrow next to the navigation title

arrowPadding - Padding between the navigation title and arrow. Default is 15

maskBackgroundColor - Mask layer color Default is blackColor()

maskBackgroundOpacity - Opacity of the mask layer Default is 0.3

menuTitleColor - Title color displayed in the menu. Default is lightGrayColor()

shouldKeepSelectedCellColor - Selected cell color visibility when menu is shown Default is false

shouldChangeTitleText - Ability to change the selected title text Default is true

selectedCellTextLabelColor - Selected cell text label color Default is darkGrayColor()

arrowTintColor - Tint color of the arrow. Default is whiteColor()

Requirement

  • iOS 8.0+ (CocoaPods with Swift support will only work on iOS 8.0+. Alternatively, you will have to import library manually to your project)
  • Xcode 8.0+, Swift 3.0+

Changelog

See the CHANGELOG for details

License

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

btnavigationdropdownmenu's People

Contributors

phambatho avatar tuanphung avatar smartphone-pro avatar rickerbh avatar ninjarz avatar naoyashiga avatar bkrastev avatar bclymer avatar vortec4800 avatar farshidce avatar lookfirst avatar justindhill avatar kriskelly avatar frostover avatar skywinder avatar readmecritic avatar rishabhtayal avatar thorin-grab avatar zkrige avatar ilyailya avatar

Stargazers

 avatar

Watchers

James Cloos 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.