If we want that when we tap on a UITextField then date picker should show, so we can use following code-
[yourTextFieldOutlet setInputView:_datePicker];// _datePicker is the DatePicker type property
Here we want to add done button on a DatePicker and once click on it DatePicker should hide.
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolBar.barStyle = UIBarStyleBlackOpaque;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTouched:)];
[toolBar setItems:[NSArray arrayWithObjects:doneButton,nil]];
_yourTextFieldOutlet.inputAccessoryView = toolBar;
- (void)doneTouched:(UIBarButtonItem *)sender
{
// hide the picker view
[_yourTextFieldOutlet resignFirstResponder];
// perform some action
}
0 Comment(s)