Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a dropdown menu to the Navigation Bar Title in iOS

I want to make something similar to the dropdown menu in these screenshots. How would I go about doing that?

enter image description here

When you tap the title, the arrow points up and a menu drops down. The App Is College Menus.

enter image description here

like image 380
TheBrownCoder Avatar asked Jul 24 '15 18:07

TheBrownCoder


People also ask

How do I add a menu to the navigation bar?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.

What is drop down navigation menu?

A drop-down menu is a clean method of showing a large list of choices since only one choice is displayed initially until the user activates the drop-down box. To add a drop-down menu to a web page, you would use a <select> element.


1 Answers

There are lots of cocoacontrols to perform this function in your app:

DropDown Menu Controls For iOS

But I think lmdropdownview is the most accurate.

My mistake, btnavigationdropdownmenu ITS the most accurate for what you are asking (according to your screens).

Implementation (Swift)[See the readme for more speceific instructions, and customization]:

let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"]

let menuView = BTNavigationDropdownMenu(frame:  CGRectMake(0.0, 0.0, 300, 44), title: items.first!, items: items, containerView: self.view)

self.navigationItem.titleView = menuView

menuView.didSelectItemAtIndexHandler = {(indexPath: Int) -> () in
            println("Did select item at index: \(indexPath)")
            self.selectedCellLabel.text = items[indexPath]
}

Hope it helps.

EDIT:

Thanks for 'rsc' for the info, theres an objective-c version of this cocoacontrol:

    #import "PFNavigationDropdownMenu.h"


-(void)viewDidLoad{
    PFNavigationDropdownMenu *menuView = [[PFNavigationDropdownMenu alloc]initWithFrame:CGRectMake(0, 0, 300, 44)title:items.firstObjects items:items containerView:self.view];

    menuView.didSelectItemAtIndexHandler = ^(NSUInteger indexPath){
            NSLog(@"Did select item at index: %ld", indexPath);
            self.selectedCellLabel.text = items[indexPath];
        };

        self.navigationItem.titleView = menuView;

    }
like image 193
Karlo A. López Avatar answered Sep 26 '22 10:09

Karlo A. López