UIDatePicker is nice UI component which is used for visually date manipulation in application. Like UIPickerView component explained in previous tutorial Using UIPickerView component into your iOS App this component is return selected date by giving us possibility for selecting. We can find this component implemented in applications where we need to select date of birth, expiration date etc.
In this tutorial we will develop very basic example just to have an idea how this component can be implemented.
Like in previous tutorials we are starting from beginning.
We are starting with creating the Single View Application in our Xcode IDE.
Next we are setting Product Name, Organisation Name, Identifier, Language ( Objective-C or Swift ) and Device.
Your project should look like this after finishing previous step:
Next we are setting the size of the view and we are choosing compact, portrait for all iPhones.
We are dropping from the Object Library one UIDatePicker and one UILabel components.
Next from the InterfaceBuilder in Assistant Editor we are creating IBOutlet for label which will be used for displaying selected value in our example.
With dragging from the InterfaceBuilder to Assistant Editor we are making one action method which will be executed by changing the value on our UIDatePicker component with picking the date.
After that in this method we are writing some basic date to string conversation logic so can we display returned date object from UIDatePicker component as string in our label.
When we compile and run the application in the simulator we can try selecting different dates in our component so we can see if everything we have implemented correctly how its working.
Complete source code can be found on my GitHub ready for testing.