Display Time Picker On Textfield Click in Xcode
Tech-Today

Display Time Picker On Textfield Click in Xcode


Open Xcode and create a new Single View Application. For product name, use TextFieldTimePicker and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices.


For setting up the user interface, first, I embed the view controller inside a navigation controller. Go to Interface Builder, and then click the View Controller. Once the View Controller has been clicked, select the "Editor" -> "Embed in" -> "Navigation Controller".

Next, let's add a bar button item, a label, and a text field. I configured the bar button item to have a title of "Done". I also changed the label text to "00:00" and textfield's placeholder to "Input Time Here".

We will need to connect the user interface's to the view controller. Select the assistant editor and open the ViewController.m file. Ctrl and drag from the "Done" button to the class section and create the following action.


Repeat the same process for label and textfield, except that they should be an outlet and not an action.
 

Inside the ViewController.m, add the following lines of code to set-up the date picker and make it the input view of the text field:

-(void)setUpTextFieldDatePicker
{
UIDatePicker *datePicker = [[UIDatePicker alloc]init];
datePicker.datePickerMode = UIDatePickerModeTime;
[datePicker setDate:[NSDate date]];
[datePicker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];
[self.txtField_timeTextField setInputView:datePicker];
}

-(void)updateTextField:(id)sender
{
UIDatePicker *picker = (UIDatePicker*)self.self.txtField_timeTextField.inputView;
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm"]; //24hr time format
NSString *dateString = [outputFormatter stringFromDate:picker.date];

self.self.txtField_timeTextField.text = [NSString stringWithFormat:@"%@",dateString];
}

Then, we'll have to set up the date picker once the view controller is loaded. Call the setUpTextFIeldDatPicker inside the viewDidLoad
[self setUpTextFieldDatePicker];

Inside the btn_showTime, add the following lines of code to update the label and hide the date picker once the button is cliced.
 
self.lbl_timeLabel.text = self.txtField_inputTextfield.text;
[self.txtField_inputTextfield resignFirstResponder];
Build and Run, a date picker should now appear when the text field is clicked.

You can download the source code of the TimeTextField at my repository on bitbucket.






- Simple To-do List Using Core Data In Swift
Note: The steps 1-9 are all simply about setting-up the controllers. The main "core data" begins the next step after. Here's the finish project from step-1 to step-9. 1.) First, for us to have a better view, we have to disable the size classes....

- Create A Simple Table View App In Xcode
Open Xcode and create a new Single View Application. For product name, use SimpleTableView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. Drag a table view inside the view controller....

- Xcode: Create A Simple Alertview
Open Xcode and create a new Single View Application. For product name, use SimpleAlertView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. Drag a button inside the view controller...

- How To Differentiate Between 3.5 And 4 Inch Iphone
Open Xcode and create a new Single View Application. For product name, use DifferentiateIphoneSize and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. For demonstration purposes, add a...

- Add A Jquery Datepicker On Jquery Dialog Box Via Load Method
Recently I've worked on a form that requires a jquery datepicker to be rendered inside jquery's dialog element. Where I encountered several problems like: 1.) datepicker() should be invoke inside dialog 2.) the dialog created (div) should be remove...



Tech-Today








.