Reputation: 1493
I am trying to add a UISlider
to a UIView
to add to my UIAlertController
for an easier but am unsure of the method. In Objective C you would call addSubview
but I am unsure of what it is in swift.
//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)
Upvotes: 2
Views: 1134
Reputation: 2269
In swift you can use addSubView too.
parentView.addSubView(childView)
In your case you would do
view.view.addSubView(slider)
To add to the UIAlertController
you have to access its view
property like so:
refreshAlert.view.addSubView(view.view)
Upvotes: 7