ios 单击按钮时弹出 UIPickerView (Swift)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31196722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:42:05  来源:igfitidea点击:

Pop up UIPickerView on button click (Swift)

iosswiftuipickerview

提问by Josh O'Connor

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.

如何通过单击按钮弹出 UIPickerView(不在屏幕上)?我在网上找不到任何可以做到这一点的来源。

回答by Dhaval Mistry

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.

如果您想在按钮单击时弹出选择器视图...您可以使用 uitextfield 而不是 uibutton .... 在 ViewDidload 中只需将 uitextfield inputview 设置为选择器视图,并在文本字段 Didbeginediting 中将文本字段色调颜色设置为 Clearcolor。

Try this, Hope it Helps.

试试这个,希望它有帮助。

回答by nachshon f

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.

  1. 在 main.storyboard 文件的视图控制器中创建一个 UIView 并在其中添加一个 UIPicker 视图。

  2. 使用 IBOutlet 将视图和选择器视图连接到 viewController.swift

  3. 在 ViewDidLoad 方法中,隐藏我们创建的 uiview。

  4. 单击按钮时,取消隐藏您创建的 uiview,并获取用户输入。

Here is an example...

这是一个例子...

enter image description here

在此处输入图片说明