Call UIPickerView when a button is pressed (Swift)

How can I open a UIPickerView (which is missing on the screen) by clicking a button? I can not find sources on the Internet that do this.

+6
source share
2 answers

Follow these steps ...

  • create a UIView in the view controller in the main.storyboard file and add the UIPicker view to it.

  • connect view and view of choice to viewController.swift using IBOutlet

  • in the ViewDidLoad method, hide the uiview we created.

  • when the button is pressed, display the uiview created and get user input.

Here is an example ...

enter image description here

+9
source

if you want popUp pickerview to click the button ... you can use uitextfield instead of uibutton .... in ViewDidload just set the input value of uitextfield as vieweriew and in the Didbeginediting text box set the color of the text in the text as Clearcolor.

Try this, hope this helps.

+10
source

All Articles