单击按钮弹出 UIPickerView (Swift)

Pop up UIPickerView on button click (Swift)

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

按照这些步骤...

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

  2. 使用 IBOutlet

  3. 将视图和选择器视图连接到 viewController.swift
  4. 在ViewDidLoad方法中,隐藏我们创建的uiview。

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

这是一个例子...

如果您想在单击按钮时弹出 pickerview ...您可以使用 uitextfield 而不是 uibutton ...。在 ViewDidload 中只需将 uitextfield inputview 设置为 pickerview 并在 textfield Didbginediting 中将 textfield tint color 设置为 Clearcolor。

试试看,希望对您有所帮助。