怎么在UIAlertView
中显示Uistepper
?请高手指点一下,我需要在工程中用到。还有如何在弹出窗口中显示UIStepper
。
ChatGPT尝试为您解答
在 iOS 13 及以后的版本中,UIAlertView 已经不再被支持。它被替换为了 UIAlertController 类。你可以使用 UIAlertController 来创建一个弹出窗口,并在其中添加 UIStepper 控件。
你可以使用以下代码来创建一个包含 UIStepper 的 UIAlertController:
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
let stepper = UIStepper()
stepper.minimumValue = 0
stepper.maximumValue = 100
stepper.stepValue = 1
alertController.view.addSubview(stepper)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelAction)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
在这段代码中,我们首先创建了一个 UIAlertController 实例,然后创建了一个 UIStepper 实例,并设置了其最小值、最大值和步长。接着,我们将 UIStepper 添加到了 UIAlertController 的 view 中。最后,我们为 UIAlertController 添加了一个取消按钮和一个确定按钮,然后使用 present 方法显示弹出窗口。