如何将UIStepper添加到AlertView

时间:2017-01-07 21:18:41

标签: ios swift uikit uistepper

我想在我的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()

2 个答案:

答案 0 :(得分:0)

UIAlertView已弃用。您应该使用UIAlertController代替。这是一个答案,解释了如何使用UIAlertController实现您想要的东西:

UIAlertController - add custom views to actionsheet

答案 1 :(得分:0)

//  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)