Open Xcode together with produce a novel Single View Application. For production name, piece of job TextFieldTimePicker together with and then produce sum out the Organization Name together with Company Identifier amongst your customary values. Select iPhone for Devices.
For setting upwardly the user interface, first, I embed the persuasion controller within a navigation controller. Go to Interface Builder, together with and then click the View Controller. Once the View Controller has been clicked, choose the "Editor" -> "Embed in" -> "Navigation Controller".
Next, let's add together a bar push item, a label, together with a text field. I configured the bar push detail to bring a championship of "Done". I equally good changed the label text to "00:00" together with textfield's placeholder to "Input Time Here".
We volition ask to connect the user interface's to the persuasion controller. Select the assistant editor together with opened upwardly the ViewController.m file. Ctrl together with drag from the "Done" push to the flat department together with produce the next action.
Repeat the same procedure for label together with textfield, except that they should move an outlet together with non an action.
Inside the ViewController.m, add together the next lines of code to set-up the engagement picker together with arrive the input persuasion 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 fourth dimension format NSString *dateString = [outputFormatter stringFromDate:picker.date]; self.self.txtField_timeTextField.text = [NSString stringWithFormat:@"%@",dateString]; }Then, we'll bring to ready the engagement picker in i lawsuit the persuasion controller is loaded. Call the setUpTextFIeldDatPicker within the viewDidLoad
[self setUpTextFieldDatePicker];
Inside the btn_showTime, add together the next lines of code to update the label together with shroud the engagement picker in i lawsuit the push is cliced.
self.lbl_timeLabel.text = self.txtField_inputTextfield.text; [self.txtField_inputTextfield resignFirstResponder];Build together with Run, a engagement picker should instantly seem when the text champaign is clicked.
You tin post away download the beginning code of the TimeTextField at my repository on bitbucket.
0 komentar:
Please comment if there are any that need to be asked.