简体   繁体   中英

Pop up UIPickerView on button click (Swift)

How do I pop up a UIPickerView (which is not on the screen) with a button click? I can't find any sources online which do this.

if you want to popUp pickerview on button click ... you can use uitextfield instead of uibutton .... in ViewDidload just set uitextfield inputview as pickerview and in In textfield Didbeginediting set textfield tint color as Clearcolor.

Try this, Hope it Helps.

Follow these steps...

  1. create a UIView in a view controller in the main.storyboard file and add a UIPicker view inside it.

  2. connect the view and the picker view to the viewController.swift with a IBOutlet

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

  4. when the button is clicked, unhide the uiview you created, and get the user input.

Here is an example...

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM