Reputation: 153
Is there a way to set the date of the UIDatePicker to be dynamic? How can I set the Minumum Date
to be the current date?
Upvotes: 1
Views: 1532
Reputation: 2688
This is very simple Datepickerview with minimum date set to Today
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// Create a DatePicker
let datePicker: UIDatePicker = UIDatePicker()
// Posiiton date picket within a view
datePicker.frame = CGRect(x: 10, y: 50, width: self.view.frame.width, height: 200)
// Set some of UIDatePicker properties
datePicker.timeZone = NSTimeZone.local
datePicker.backgroundColor = UIColor.white
datePicker.datePickerMode = .date
datePicker.minimumDate = Date()
self.view.addSubview(datePicker)
}
}
Upvotes: 2