i need to change the text of the button "return" on my keyboard,and i even need to change its action. The action should be a new paragraph. Can you help me?
-
Do you need it for an `UITextField` or an `UITextView`? – pteofil May 04 '15 at 13:01
-
You can write the code in Delegate method of UITextField.. -(BOOL)textFieldShouldReturn; and it it possible to change the name of return button through IB property – Ashok Londhe May 04 '15 at 13:04
-
do you want to change text "return " also ? in keyboard – Sport May 04 '15 at 13:19
-
I've used a UITextfield,and i want to change text "return " – Gianluca Carpi May 04 '15 at 13:27
5 Answers
You cannot rename the Return button to any custom text
Some default values thatThe return key can take are
typedef enum : NSInteger {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
} UIReturnKeyType;
where Default is "return" others are Go, Google, Yahoo as is.
look here.
And for capturing the return Event you can use the textView Delegate method
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([text isEqualToString:@"\n"]) {
NSLog(@"Pressed Return Key");
} else {
NSLog(@"Pressed Any Other Key");
}
return YES;
}

- 4,943
- 30
- 34
UITextField has this delegate method that you can implement, and get's called when you press return on the keyboard:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
You can add a new line char "\n" to the textView text and it would go to next line.
UITextView
it's suppose to work like that where it would go to a new line when you press Return.

- 4,133
- 17
- 27
click and set your keyword here
[textField setReturnKeyType:UIReturnKeyDone];
for keyboard implement the protocol in your class, set
textfield.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// write you code here what you want .
return YES;
}
refer this if you want to UITextView How to dismiss keyboard for UITextView with return key?
Here is the way to add custom button over the keyboard. But apple could reject your app so be careful.
- (void)viewWillAppear:(BOOL)animtated {
// Register the observer for the keyboardWillShow event
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animtated {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardWillShow:(NSNotification *)notification {
// create custom buttom
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(self.view.frame.size.width- 100, self.view.frame.size.height - 200.0f, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton addTarget:self action:@selector(addParaGraph:) forControlEvents:UIControlEventTouchUpInside];
[doneButton setBackgroundColor:[UIColor redColor]];
[doneButton setTitle:@"Add Paragraph" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView *keyboard;
for (int i = 0; i < [tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
//if ([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) {
[keyboard addSubview:doneButton];
//}
}
}
- (void)addParaGraph:(id)sender{
// Write here you code to add new paragraph
}
-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
// Set the FirstResponder of the UITextField on the layout
[theTextField resignFirstResponder];
return YES;
}

- 3,529
- 2
- 18
- 31
Swift 3
let addressTextField = UITextField()
addressTextField.placeholder = "Search or enter website name"
addressTextField.layer.borderColor = UIColor.gray.cgColor
addressTextField.layer.borderWidth = 1.0
addressTextField.returnKeyType = .go
view.addSubview(addressTextField)
addressTextField.delegate = self
extension YourNaneController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}

- 3,553
- 30
- 28