Back to blogging in 2020!

Dropdown-menu-like-things on iOS made from UIPickerView and UITextField

All the code on the internet that shows how to do this is broken and/or doesn't provide enough context.

I wanted something that would serve the same purpose as an HTML drop down menu, without necessarily acting exactly like one. Got some clues and ideas for different ways of handling it from @commanda, and ultimately got this slick and simple way to work.

It's one part understanding UIPickerViews and how to make them go, and one part setting the inputView of a UITextField to reference a particular picker. And yet another part making the picker hide itself when you tap on the background. And then throw in handling multiple pickers at once.

CODE HERE! https://gist.github.com/ktuite/fc23de2f129458630f18

Whee, a picker slides up from the bottom (instead of a keyboard) to fill in the text field

There it is again, not as a vine this time.

My storyboard just has two text fields (which each use a different UIPickerView as an inputView)
I have the it's complicated gender option based on the advice/insight of this article: Designing a Better Drop-Down Menu for Gender

Comments