12

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

2 Answers 2

18

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;

    }
1
6

Possible workaround if you prefer doing it manually:

Create two UIButton (up/down), assign the first one to navigationItem.titleView, add action for UIControlEventTouchUpInside on this action check if states changing to expanding or collapsing and dependent on that add/remove UITableView with empty dataSource on top of your UIViewController view, set proper frame. Then update datasource and either reload with row animation UITableViewRowAnimationBottom or UITableViewRowAnimationTop dependent on if it's expanding or collapsing. Replace button with second one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.