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 le
Today just use myTextField.keyboardAppearance = .dark
Updating to swift 3.0
let textFieldAppearance = UITextField.appearance()
textFieldAppearance.keyboardAppearance = .dark //.default//.light//.alert
If you're using Interface Builder, you can set keyboard look in the Attributes Inspector:
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://stackoverflow.com/a/5337804/588253), you can use this:
mytextfield.keyboardAppearance = (SYSTEM_VERSION_LESS_THAN(@"7.0") ? UIKeyboardAppearanceAlert : UIKeyboardAppearanceDark);
SWIFT 4+: in the AppDelegate
UITextField.appearance().keyboardAppearance = .dark
Swift 5+ (TextView)
textView.keyboardAppearance = .dark