Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add target to keyboard done/go/search buttons?

I want to attach a action to button, which is on keyboard. I don't want to create a custom keyboard, only handle search/go/done buttons actions.

enter image description here

Thanks!

like image 718
gkhanacer Avatar asked Oct 20 '25 12:10

gkhanacer


1 Answers

To handle return Key you Use delegate textFieldShouldReturn

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
         // your Action According to your textfield
        return true
    }

How to change Return Key

yourTextField.returnKeyType = UIReturnKeyType.search
yourTextField.returnKeyType = UIReturnKeyType.done

Apple Enum :

typedef NS_ENUM(NSInteger, UIReturnKeyType) {
    UIReturnKeyDefault,
    UIReturnKeyGo,
    UIReturnKeyGoogle,
    UIReturnKeyJoin,
    UIReturnKeyNext,
    UIReturnKeyRoute,
    UIReturnKeySearch,
    UIReturnKeySend,
    UIReturnKeyYahoo,
    UIReturnKeyDone,
    UIReturnKeyEmergencyCall,
    UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),
}
like image 174
Abdelahad Darwish Avatar answered Oct 23 '25 04:10

Abdelahad Darwish