2015-05-27 110 views
1

我想添加一個UISliderUIView添加到我的UIAlertController爲更容易,但我不確定的方法。在目標C中,您可以撥打addSubview,但我不確定它是什麼。添加UISlider到UIView

//UIViewController.alertReminden(timeInterval) 

      var refreshAlert = UIAlertController(title: "Reminder", message: "Set a reminder for the bus in \(self.timeInterval) minutes.", preferredStyle: UIAlertControllerStyle.Alert) 

      refreshAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action: UIAlertAction!) in 
       Alarm.createReminder("Catch the Bus", 
        timeInterval: NSDate(timeIntervalSinceNow: Double(self.timeInterval * 60))) 
      })) 

      refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in 
       println("Handle Cancel Logic here") 
      })) 

      var view = UIViewController(); 


      var myFrame = CGRectMake(10.0, 10.0, 250.0, 25.0) 

      var slider = UISlider(frame: myFrame) 

      slider.minimumValue = 1 
      slider.maximumValue = 50 
      slider.value = Float(timeInterval) 

      view.addSubview(slider) 

      refreshAlert.addChildViewController(view) 



      self.viewForBaselineLayout()!.parentViewController?.presentViewController(refreshAlert, animated: true, completion: nil) 

回答

6

在swift中,你也可以使用addSubView。

parentView.addSubView(childView) 

在你的情況,你會怎麼做

view.view.addSubView(slider) 

爲了增加UIAlertController你要訪問其view屬性,像這樣:

refreshAlert.view.addSubView(view.view) 
+0

這的確然而工作的看法仍然不顯示在UIAlertController – applejuiceteaching

+0

你有沒有嘗試'refreshAlert.addSubView(view.view)'? – Chackle

+0

UIAlertController沒有addSubView方法只有refreshAlert.addChildViewController()需要一個UIViewController而不是UIView – applejuiceteaching