black friday sale

Flat 10% off on the purchase of any two apps or more. Use coupon code - FESTIVAL10

Grab It Now
Check Mobile App
Read now
Start a Project

Add Date and Time Picker View in UITextField (Swift)

Save

Date & Time picker View

Some times we need to pick date or time in application for this we have to create the separate   UIView and add UIDatePicker then perform functionality on it. swift provide default feature in UITextField where we need to add view as UIDatepicker so when we tap on it , this will show the respective data whatever you have set on UIDatepicker mode.

There is Various mode of UIDatePicker

a: date picker , time picker, date & Time picker.

For doing this , you have to follow this steps.

1: take a UITextfield in UIViewcontroller and create their outlet like

@IBOutlet weak var sampleDateTextField: UITextField!

2: Now Create the outlet as ActionMode and set editing method as didbeginedit ( this will work when you just tap on UItextfield)

like as

@IBAction func specialDateTextFieldClick(_ sender: UITextField) {}

3: Now define the method

4: Here I have set action , it will call  this static method ”

Here  “ProductAttributeField” is class and name of method is  “datePickerFromValueChanged

Note: you can set date picker mode according to your requirement.

5: Now it time to define their method like that.

Here I have set formatter ,it is required to display the date or you can set different formatter .

6: Now you tap on UITextField then datepicker will show and on changing then automatic fill the date on UItextField.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


3 comments

  • trapti dubey
    after setting time time picker is not hiding itself ? as I wrote time.is hidden = true what is the solution
    • kunal prasad (Moderator)
      just call this after filling the time ” view.endEditing(true)”
      it will remove the keyboard.
  • Gayani Gunawardhana
    how to display the time with the date?
  • css.php

    Very good company, we did get app extension for Magento 2 website. The support was very good they help us through the process. Webkul team is very supportive, I would recommend them.

    Yasser Mohamed

    Yasser Mohamed

    Talk to Sales

    Global

    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home