2017-01-07 2 views
0

Я хочу добавить UIStepper к моему alerView но шагового не показывается здесь мой кодКак добавить UIStepper к AlertView

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() 
+0

Вот пример, который работает, но в Objective C :(http://stackoverflow.com/questions/14869020/uistepper-in-uialertview Может быть, это поможет вам в любом случае. –

+0

Это не сработало –

+0

Можете ли вы опубликовать свое изменение на быстрый код? Что такое ошибка? –

ответ

0

UIAlertView устарела. Вместо этого вы должны использовать UIAlertController. Вот ответ, который объясняет, как можно реализовать то, что вы хотите с помощью UIAlertController:

UIAlertController - add custom views to actionsheet

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) 
Смежные вопросы