Reputation: 672
I would like to have a Date Picker with only one wheel, filled with days as on the Date and Time mode.
If I choose the Date mode, I have 3 wheels and I loose the name of the day. In fact I would like something like the date and time mode, but only with the date.
I could use a UIPickerView, but I would have to fill it by myself with a very big array of data, as I want to be able go back far in time. With the Date picker, it's filled automatically, which is cool.
Is there a solution ?
Upvotes: 6
Views: 5453
Reputation: 1
try displayedComponents with .date
DatePicker( selection: .constant(futureDate), displayedComponents: [.date],
label: { Text("Due date") })
Upvotes: 0
Reputation: 1
datePicker.datePickerMode = UIDatePicker.Mode.date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd MMMM yyyy"
let selectedDate = dateFormatter.string(from: datePicker.date)
print(selectedDate)
Upvotes: -2
Reputation: 1698
As you only need to show the contents that you have marked in the green box. You can use this https://github.com/attias/AADatePicker and modify it a bit and you can get it as per your requirement.
The changes you will need to make are within the AADatePickerView Class
1) In viewForRow method comment the following things
Upvotes: -1
Reputation: 21144
You can also use UIDatePicker's pickerMode property to do that.
datePicker.pickerMode = .Date
Look into header file, you will see that there are few other Options that you can play with. Other values are;
Time
Date
DateAndTime
CountDownTimer
Upvotes: 6
Reputation: 2256
You should use the UIPickerView instead of the UIDatePicker. There is no possibility to customise UIDatePicker in the way you want.
Upvotes: 1