When I click inside text box, How can I add plus button to UITextField as shown in the following screen? When this button is clicked it would launch iPhone contact application. I would very much appreciate any code example. Thanks
addDoneKeyboardButton() — creates the keyboard done button using UIToolbar. Inside the toolbar, we create a UIBarButtonItem. You can name the button however you want, and you can add multiple buttons (depending on your needs). In other words, use this function to customize the toolbar.
A text field is a UI element that enables the app to get user input.
You can use the below code for this:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == yourFirstTextField)
{
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setImage:[UIImage imageNamed:@"addImage.png"] forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(yourActionHere) forControlEvents:UIControlEventTouchUpInside];
textField.rightViewMode = UITextFieldViewModeWhileEditing;
textField.rightView = addButton;
}
}
You can use the above method if you added the field in IB.
If you are created it through code, you need to add the below code when creating:
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setImage:[UIImage imageNamed:@"addImage.png"] forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(yourActionHere) forControlEvents:UIControlEventTouchUpInside];
textField.rightViewMode = UITextFieldViewModeWhileEditing;
textField.rightView = addButton;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With