dynamically change UIKeyboards return key

跟風遠走 提交于 2019-11-29 10:42:28

You can have return key customized to prefixed values that you can see in UIReturnKeyType enum for each UITextField.

textFieldName.returnKeyType = UIReturnKeyNext;
textFieldEmail.returnKeyType = UIReturnKeyDefault;

Not sure if this is what you're looking for though.

You have a chance to set up keyboard characteristics in the UITextFieldDelegate Protocol method textFieldShouldBeginEditing: which is called before the text field becomes the first responder (indeed to decide if it may become the first responder). If you don't already have a delegate for the text field(s) in question you would have to assign one and implement at least that method. Presumably the same object handling the text field could hold the delegate methods. The following implementation sets the return key to "Search".

- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    NSLog(@"textFieldShouldBeginEditing");
    textField.returnKeyType = UIReturnKeySearch;
    return YES;
}

You'd have to look at the contents of your text fields to decide what value to use.

textfield.returnKeyType = UIReturnKeySearch;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!