Is there a way to present the date picker from UIAlertControllerStyle.ActionSheet? There are ways to add buttons in ActionSheet and add actions to these buttons, but I can’t find a solution to add datepicker or any custom view in ActionSheet.
This is not possible, but when the user clicks on the text field, you can use the UItextfield input view and attachment view to display and close the date picker
class KPDatePickerViewController: UIViewController {
var datePicker:UIDatePicker!
@IBOutlet var dateTextField:UITextField!
override func viewDidLoad() {
var customView:UIView = UIView (frame: CGRectMake(0, 100, 320, 160))
customView.backgroundColor = UIColor.brownColor()
datePicker = UIDatePicker(frame: CGRectMake(0, 0, 320) , 160))
customView .addSubview(datePicker)
dateTextField.inputView = customView
var doneButton:UIButton = UIButton (frame: CGRectMake(100, 100, 100, 44))
doneButton.setTitle("Done", forState: UIControlState.Normal)
doneButton.addTarget(self, action: "datePickerSelected", forControlEvents: UIControlEvents.TouchUpInsid e)
doneButton.backgroundColor = UIColor .blueColor()
dateTextField.inputAccessoryView = doneButton
}
func datePickerSelected() {
dateTextField.text = datePicker.date.description
}
}
Is there a way to present the date picker from UIAlertControllerStyle.ActionSheet? There are ways to add buttons in ActionSheet and add actions to these buttons, but I can’t find a solution to add datepicker or any custom view in ActionSheet.
This is not It is possible, but when the user clicks on the text field, you can use the UItextfield input view and attachment view to show and close the date picker
class KPDatePickerViewController: UIViewController {
var datePicker:UIDatePicker!
@IBOutlet var dateTextField:UITextField!
override func viewDidLoad() {
var customView:UIView = UIView (frame: CGRectMake(0 , 100, 320, 160))
customView.backgroundColor = UIColor.brownColor()
datePicker = UIDatePicker(frame: CGRectMake(0, 0, 320, 160))
customView .addSubview( datePicker)
dateTextField.inputView = customView
var doneButton:UIButton = UIButton (frame: CGRectMake(100, 100, 100, 44))
doneButton.setTitle("Done", forState: UIControlState .Normal)
doneButton.addTarget(self, action: "datePickerSelected", forControlEvents: UIControlEvents.TouchUpInside)
doneButton.backgroundColor = UIColor .blueColor()
dateTextField.inputAccessoryView = doneButton
}
func datePickerSelected() {
dateTextField.text = datePicker.date.description
}< br />}