Search code examples
iosiphonexcodeuidatepicker

How to use one UIDatePicker to display only time on one button click and only date on another?


Im working on an app where in a single view controller I have a date button and a time button. I want to put one date picker in the view. I want that single date picker to display only date on the date button click and only time on the time button click. How is this possible?


Solution

  • Please set your mode using following property as per your requirement :

    @property(nonatomic) UIDatePickerMode datePickerMode
    

    Change your mode in your button actions appropriately.

    For example, lets say you have UIDatePicker *datePicker;

    you can set mode using below code :

    datePicker.datePickerMode = UIDatePickerModeTime;