Control DatePicker from Text Field Ios

How to create a text field that controls a UIDatePicker on Ios.

See the Code: https://github.com/timleland/Ios-UIDatePicker

Screen Shot 2015-02-09 at 9.49.25 PM

 

Create a new single view application.

Screen Shot 2015-02-09 at 9.32.21 PM

Make sure to select Objective C

Screen Shot 2015-02-09 at 9.32.26 PM

On the main storyboard drag the Datepicker object to the view

Screen Shot 2015-02-09 at 9.33.11 PM

Then drag the Toolbar above the Datepicker

Screen Shot 2015-02-09 at 9.33.31 PM

Drag the flexible space bar button item to the left of the ‘Item’ button. This will push the ‘Item’ button the the far right.

Screen Shot 2015-02-09 at 9.33.55 PM

Change the ‘Item’ button to ‘Done’

Screen Shot 2015-02-09 at 9.33.55 PM

Open the Assistence editor and ‘ctrl’ drag the toolbar, datepicker and text field to the ViewController.h file

Screen Shot 2015-02-09 at 9.35.50 PM

To fix constraints so the app will look good on other devices click ‘Reset to suggested constraints’

Screen Shot 2015-02-09 at 9.37.36 PM

Connect actions for text field to show the datepicker

Screen Shot 2015-02-09 at 9.44.12 PM

Connect the ‘Done’ button to the close date picker action

Screen Shot 2015-02-09 at 9.48.05 PM

Connect the datepicker change to the action

Screen Shot 2015-02-09 at 10.10.34 PM

 

Let me know in the comments if you have any questions!


Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LYWeather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.  

Leave a Reply

Your email address will not be published.