【问题标题】:How to add a UIStepper to AlertView如何将 UIStepper 添加到 AlertView
【发布时间】:2017-05-22 10:53:14
【问题描述】:

我想向我的alerView 添加一个UIStepper,但步进器没有显示在这里是我的代码

 var alert = UIAlertView(title: "Hello works", message: "\n\n", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "")
 var stepper = UIStepper()
    stepper.frame = CGRect(x: CGFloat(12.0), y: CGFloat(5.0), width: CGFloat(100), height: CGFloat(10))
    alert.addSubview(stepper)
    alert.show()

【问题讨论】:

  • 这是一个有效的例子,但它是在目标 c :( stackoverflow.com/questions/14869020/uistepper-in-uialertview 无论如何它可能对你有帮助。
  • 它没有用
  • 您可以将您的更改发布到 swift 代码吗?说明什么错误?
  • 这是更改,它没有给出任何错误,只是没有显示在警报视图中
  • 无论如何都看不到变化,试着移动这个值:stepper.frame = CGRect(x: CGFloat(12.0), y: CGFloat(5.0), width: CGFloat(100), height: CGFloat (10)) 也许您正在绘制警报。

标签: ios swift uikit uistepper


【解决方案1】:
//  Below is code for implementing UIAlertView Using UIAlertController in swift and add your custom views on it .


        let logoutAlert = UIAlertController(title: "Alert", message: "DemoAlert", preferredStyle: UIAlertControllerStyle.alert)



        logoutAlert.addAction(UIAlertAction(title: "cancel", style: .default, handler: nil))



        logoutAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in

            // Write your code here

        }))

        var stepper = UIStepper()
        stepper.frame = CGRect(x: CGFloat(12.0), y: CGFloat(5.0), width: CGFloat(100), height: CGFloat(10))

        // You can add any view on UIAlert controller using below code:

        logoutAlert.popoverPresentationController?.sourceRect = stepper.frame

        logoutAlert.popoverPresentationController?.sourceView = stepper


        self.present(logoutAlert, animated: true, completion: nil)

【讨论】:

    【解决方案2】:

    UIAlertView 已弃用。您应该改用UIAlertController。这是一个解释如何使用 UIAlertController 实现所需内容的答案:

    UIAlertController - add custom views to actionsheet

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 1970-01-01
      • 2016-03-03
      相关资源
      最近更新 更多