Skip to content

Instantly share code, notes, and snippets.

@allenatwork
Created April 5, 2017 07:21
Show Gist options
  • Save allenatwork/9e1cec5cf45847e20b9fcf5f5c1285d3 to your computer and use it in GitHub Desktop.
Save allenatwork/9e1cec5cf45847e20b9fcf5f5c1285d3 to your computer and use it in GitHub Desktop.
Show done button for UITextView
// Add toolbar to above keyboard
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
_tvContent.inputAccessoryView = numberToolbar;
// Action when click done
- (void) doneWithNumberPad{
[_tvContent resignFirstResponder];
}
// Doi voi TextField thì có thể trực tiếp hiện nút done ở keyboard
_tfTitle.returnKeyType = UIReturnKeyDone;
// Sau do
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
//eturn YES;
// [self.view endEditing:YES];
[textField resignFirstResponder];
return YES;
}
// Remember : controller phai implement TextFieldDelegate
textField.delegate =self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment