Search code examples
iphoneiosxamarin.iosuikeyboarduikeyboardtype

How to change the return key of UIKeyboard with customized button for iPhone using MonoTouch?


I need to add a button to UIKeyboard in the place of Return key and also need to raise events for that customized button for iPhone using MonoTouch.


Solution

  • Take a look at the UITextInputTraits protocol. It defines a returnKeyType (UIReturnKeyType) which can be

    typedef enum {
       UIReturnKeyDefault,
       UIReturnKeyGo,
       UIReturnKeyGoogle,
       UIReturnKeyJoin,
       UIReturnKeyNext,
       UIReturnKeyRoute,
       UIReturnKeySearch,
       UIReturnKeySend,
       UIReturnKeyYahoo,
       UIReturnKeyDone,
       UIReturnKeyEmergencyCall,
    } UIReturnKeyType;
    

    The UITextField and UITextView classes support this protocol. I don't think you can customize it further unless you do some very hacky stuff.

    If you have a UITextField then you can implement

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    

    and if you have a UITextView you can implement

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    

    both delegate methods, to determine the behaviour on return.