Add Finish and New Line buttons on the keyboard in the iPhone app

I created a window-based application with a UITabbarController as a RootViewController . On one of the tabs, I provided UITextField and UITextView . I want to provide two buttons on the keyboard itself:

  • Done - that will hide the keyboard.
  • Enter - for a new line.

Please write your answer if someone knows how to do this.

+4
source share
3 answers

For UITextField, you can change the return key to a ready-made key by setting the following:

 targetTextField.returnKeyType = UIReturnKeyDone; 

However, you cannot enter the Enter and Done key at the same time without adding custom views to the keyboard.

In addition, to control the behavior of the keyboard, you must implement the UITextFieldDelegate method:

 targetTextField.delegate = self; - (BOOL)textFieldShouldReturn:(UITextField *)textField{ return YES; //dismisses the keyboard } 

I know that you can set returnKeyType for a UITextView, but I'm not sure if you can manipulate the behavior of the returned key.

+4
source

You have a tutorial on how to add subviews to your iPhone keyboard here:

http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/7350-adding-subviews-custimize-keyboard.html

Hope this helps, Vincent

+1
source

For some reason, return YES; didn't work on its own. which worked for me:

 - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField.returnKeyType == UIReturnKeyNext) { NSInteger nextTag = textField.tag + 1; // Try to find next responder UIResponder* nextResponder = [textField.superview viewWithTag:nextTag]; if (nextResponder) { // Found next responder, so set it. [nextResponder becomeFirstResponder]; } } if (textField.returnKeyType == UIReturnKeyDone) { [textField resignFirstResponder]; } return YES; //dismisses the keyboard } 
+1
source

Source: https://habr.com/ru/post/1338079/


All Articles