Adding a cancel button to UITextField keyboard

后端 未结 3 993
旧巷少年郎
旧巷少年郎 2021-01-11 20:29

Is there a way to add a cancel button to the keyboard displayed for UITextField? Looking over the UITextInputTraits Protocol Reference, I could not

3条回答
  •  温柔的废话
    2021-01-11 21:10

    Andrew, how's it going? it's Dima R!

    As far as I know, there is no great way to do what you're trying to do. You can easily pick from one of the built in types that are listed here

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

    What you could do is either add a view on top of the keyboard that contains your cancel button, or try to traverse through the view hierarchy and overlay what you want on the button that way (although this method is unreliable). Unfortunately, this is one thing Apple has not provided much customization for yet.

    edit: Actually I think I misread your question from the start, since you wouldn't want a cancel button as the main return button anyways. In this case, the input accessory view is definitely the way to go.

提交回复
热议问题