1

I am making an app, uses UIDatePicker component. Everything works fine with the below code.

myDatePicker.datePickerMode = UIDatePickerMode.Date

My problem is here how to avoid the year column, days and months are the only data that i want to show in the component.

Like:

2 November
3 November

thanks

Özgür Ersil
  • 6,909
  • 3
  • 19
  • 29

1 Answers1

1

This is a bit tricky but if you don't have to deal with date formats and locale it may work for you.

Place the UIDatePicker inside a UIView and align all sides to the containing view's edges. Then change the right side constraint from 0 to -100 (you may have to find a different number depending on the size you want to give it).

In the containing UIView's User Defined Runtime Attributes add a key named clipsToBounds, make it a Boolean and make sure it is checked.

This will hide the edge of the Date Picker that is aligned beyond the UIView's right side.

Make sure you set a minimum and maximum date for January 1st to December 31st of a specific year (so the user doesn't accidentally go outside that year and you don't have to deal with multiple years).

Alain T.
  • 40,517
  • 4
  • 31
  • 51