I would like to know how to change the keyboard background color programmatically in iOS? The background is normally grey but I have already seen black background (behind letters).
For the dark background use:
mytextfield.keyboardAppearance = UIKeyboardAppearanceAlert;
Read to find more information about UITextInputTraits (use UIKeyboardAppearanceDark
at iOS 7+).
To change it globally, you can use appearance proxy in AppDelegate... I've tested it in iOS 8, Swift:
UITextField.appearance().keyboardAppearance = UIKeyboardAppearance.dark
In iOS 7, UIKeyboardAppearanceAlert
is deprecated, so use this instead:
mytextfield.keyboardAppearance = UIKeyboardAppearanceDark;
If you need to support both earlier iOSes and iOS 7, and you've created the necessary macros (per https://mcmap.net/q/23741/-how-to-check-ios-version), you can use this:
mytextfield.keyboardAppearance = (SYSTEM_VERSION_LESS_THAN(@"7.0") ? UIKeyboardAppearanceAlert : UIKeyboardAppearanceDark);
Updating to swift 3.0
let textFieldAppearance = UITextField.appearance()
textFieldAppearance.keyboardAppearance = .dark //.default//.light//.alert
UITextField.appearance().keyboardAppearance = .dark
in AppDelegate will change the appearance globally. with this solution you can do it on specific text fields. –
Rois Today just use myTextField.keyboardAppearance = .dark
SWIFT 4+: in the AppDelegate
UITextField.appearance().keyboardAppearance = .dark
textView.keyboardAppearance
? The property comes from UITextInputTraits
–
Sumptuary Swift 5+ (TextView)
textView.keyboardAppearance = .dark
In Objectve-C
For Dark Keyboard
[UITextField appearance].keyboardAppearance = UIKeyboardAppearanceDark;
For Light keyboard
[UITextField appearance].keyboardAppearance = UIKeyboardAppearanceLight;
You can define this in AppDelegate to handle this globally.
© 2022 - 2024 — McMap. All rights reserved.