Created
October 10, 2016 03:07
-
-
Save IamAlchemist/c582deb518dfa0535157e1d1f9fe6115 to your computer and use it in GitHub Desktop.
a date picker in alert view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func selectDate(_ sender: UIButton) { | |
let datePicker = UIDatePicker() | |
datePicker.datePickerMode = .date | |
let alert = UIAlertController(title: "\n\n\n\n\n\n\n\n\n\n\n", message: nil, preferredStyle: .actionSheet) | |
alert.view.addSubview(datePicker) | |
datePicker.snp.makeConstraints { (make) in | |
make.centerX.equalTo(alert.view) | |
make.top.equalTo(alert.view).offset(8) | |
} | |
let ok = UIAlertAction(title: "确定", style: .default) { (action) in | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "yyyy-MM-dd" | |
let dateString = dateFormatter.string(from: datePicker.date) | |
print(dateString) | |
} | |
let cancel = UIAlertAction(title: "取消", style: .default, handler: nil) | |
alert.addAction(ok) | |
alert.addAction(cancel) | |
present(alert, animated: true, completion: nil) | |
} |
Now that's an "out of the box" thinking.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saved a life 5 years later. :)