Monday 17 November 2014

Jogendra Singh

How to make UIDatePicker in iOS with Swift

Here we are going to learn UIDatePicker in swift :-

       The Date Picker in iOS 8 provides an custom Picker View that uses multiple rotating wheels to allow users to select dates and times. In this tutorial the current selected date is presented onscreen inside a label. This tutorial is written in Swift so you will need Xcode 6. It can be downloaded at Apple's developer portal.

        Open Xcode and create a new Single View Application. For product name, use UIDatePickerSwift  and then fill out the Organization Name (ex. jogendra) and Organization Identifier (Ex. com.jogendra.datePicker) with your customary values. Enter Swift as Language and make sure only iPhone/iPad/Universal is selected in Devices.

      Drag a UILabel or  UITextField (According to your requirement ) to the View Controller change the UILabel or  UITextField text to "Select Date". Next, drag a Date Picker to the View Controller and center it. The Storyboard should look like this.

Create object of both UIDatePickerView and UITextField :- 

class ViewController: UIViewController {

    var textField:UITextField!
    var datePickerObj:UIDatePicker

And Make action of UIDatePickerView
      @IBAction  func datePickerClicked( datePicker:UIDatePicker){

Connect in Storyboard

After doing these steps  do work in function of datepicker for change value 

    @IBAction  func datePickerClicked( datePicker:UIDatePicker){
        var dateFormatter = NSDateFormatter()
        dateFormatter.dateStyle = NSDateFormatterStyle.FullStyle
        var dateStr = dateFormatter.stringFromDate(
        textField.text = dateStr

It's look like this :-
Thanks for Visit  , Also can visit on My blog Facebook page iPhone & iPad Application Development Help World and also can visit Google+ 

Jogendra Singh

About Jogendra Singh -

I'm Founder of Jogendra.Com. I love to share my bright ideas with the whole blogging community. I'm a good iPhone Application Developer. Apart from Blogging, I love to play Cricket and mobile games (Clash of clans).

Subscribe to this Blog via Email :