Ben
Ben

Reputation: 3804

UIDatePicker show today's date as "Today" to User (Swift)

I have a basic DatePicker setup showing the user date selections with a format of "Tue Sep 6", "Wed Sep 7", "Thu Sep 8", etc. I would like to make it more user friendly and if it's today's date show "Today" instead of the date. So if today is indeed Tue Sep 6, then the wheel would show something custom like "Today Sep 6", "Tomorrow Wed Sep 7", "Thu Sep 8", etc.

I know how to check what today's date is. I don't know if it's possible to swap out a row or two in a DatePicker or how to do it if it's possible.

If a custom Picker is the only approach, is there any pre-typed out arrays of all the dates out there that I could copy so I don't have to type them all out myself (ugh)? I googled this to find help here but didn't find anything.

Any thoughts on how to best figure out this problem are greatly appreciated. Thanks!

Upvotes: 2

Views: 2095

Answers (2)

Zayne ZH
Zayne ZH

Reputation: 406

Select the DatePicker in your storyboard and add the key path 'highlightsToday' of type 'Boolean' in the user defined runtime attributes, make sure the value is checked. This should replace today's date in the date picker to 'Today'

enter image description here

Upvotes: 1

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16446

yes it is possible, i have seen that anywhere but not sure is for UIPickerView or UIDatePicker, datePicker is one type of UIView and can be modified , so what you need to do is take UILabel and add subview to Date picker and set text accordingly

Upvotes: 0

Related Questions