6

In android, there is action bar with drop down menu, an example is the old Gmail app in Android:

enter image description here

As you see above, when the three-dots is clicked, a drop down menu is shown.

My Questions:

  1. I am wondering, if I want to implement the same three-dots button which shows drop down menu in iOS with Navigation Controller, how to do it?

  2. If it is not a common thing to do in iOS, what is the equivalent in iOS?

(I still want to implement it in my iOS project though)

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

4 Answers4

1

The closest I can think of is UIPopOverController for iPad. You can put a tableview in a "popover".

Sample popover

For iPhone Popover visit this tutorial

https://richardallen.me/2014/11/28/popovers.html

1

What was answered before is not true anymore. Now there are context menus.

With iOS13 there was UIMenu introduced and with iOS14 UIBarButtonItem has a menu property for that you can set a UIMenu. The menu you set there, will pop up when tapping the UIBarButtonItem. (see also https://developer.apple.com/documentation/uikit/uibarbuttonitem/3601188-menu)

You do not need to set any other action on the UIBarButtonItem (see line before last line in my sample code, action is nil).

Here is an example for having a rightBarButtonItem triggering a menu with four items.

let menuHandler: UIActionHandler = { action in
    print(action.title)
}

let barButtonMenu = UIMenu(title: "", children: [
    UIAction(title: NSLocalizedString("Identify Plant", comment: ""), image: UIImage(systemName: "viewfinder"), handler: menuHandler),
    UIAction(title: NSLocalizedString("Plant's diary", comment: ""), image: UIImage(systemName: "books.vertical"), handler: menuHandler),
    UIAction(title: NSLocalizedString("Plant's notifications", comment: ""), image: UIImage(systemName: "bell"), handler: menuHandler),
    UIAction(title: NSLocalizedString("Remove plant", comment: ""), image: UIImage(systemName: "trash"), handler: menuHandler)
])

navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Manage", style: .plain, target: self, action: nil)
navigationItem.rightBarButtonItem?.menu = barButtonMenu

// or using the initializer
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Manage", image: nil, primaryAction: nil, menu: barButtonMenu)

My answer is based on this great sample code article: https://developer.apple.com/documentation/uikit/uinavigationcontroller/customizing_your_app_s_navigation_bar

laka
  • 644
  • 8
  • 23
0

There is no built-in UI component for this in iOS, and it's not widely used in apps.

But when I need to implement it I usually use AssistoLab DropDown, it's a very easy to use, well-documented and stable library.

Mo Abdul-Hameed
  • 6,030
  • 2
  • 23
  • 36
0

That not an iOS thing. BUT that been said, the best approach would be to have do a PopOver. Here theres a good answer for a PopOver

Here theres a framework that do all the work for you.

Any here theres another good answear with a popOver

Also you can just create a simple View. And when u display it, just do an animation on the view height constraint to animate the growing.

alegelos
  • 2,308
  • 17
  • 26