How To Display A Appointment Alongside Textfield Click Alongside Swift

Displaying Date amongst TextField Click amongst Swift

First yous must accept a textfield connected to storyboard.


@IBOutlet weak var txtField_helloDatePicker: UITextField!

Next yous should accept a constant of UIDatePicker type.

let datePicker = UIDatePicker()

Then within the viewDidLoad function, yous should develop the engagement picker vogue to date

datePicker.datePickerMode = UIDatePickerMode.Date

Then to demo the engagement picker on tapping the textfield, yous should develop the input persuasion of that textfield to the engagement picker
        
txtField_helloDatePicker.inputView = datePicker

Then to larn by the changes inward the selection
        

datePicker.addTarget(self, action: Selector("datePickerChanged:"), forControlEvents: UIControlEvents.ValueChanged)

Then to conduct maintain the activity  of the engagement picker, yous should have 

func datePickerChanged(datePicker:UIDatePicker) {
        println("time picker changed for ceremony")
        
        var dateFormatter = NSDateFormatter()
        
        dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
        
        var strDate = dateFormatter.stringFromDate(datePicker.date)
        
        txtField_helloDatePicker.text = strDate
 }

Summary of Code:

datePicker.datePickerMode = UIDatePickerMode.Date
        
txtField_helloDatePicker.inputView = datePicker
        
datePicker.addTarget(self, action: Selector("datePickerChanged:"), forControlEvents: UIControlEvents.ValueChanged)

func datePickerChanged(datePicker:UIDatePicker) {
        println("time picker changed for ceremony")
        
        var dateFormatter = NSDateFormatter()
        
        dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
        
        var strDate = dateFormatter.stringFromDate(datePicker.date)
        
        txtField_helloDatePicker.text = strDate
 }
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.