How to change keyboard background color in iOS?

风流意气都作罢 提交于 2019-11-27 11:53:48
A-Live

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 = .Dark
Mr. T

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);

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:

SWIFT 4+: in the AppDelegate

UITextField.appearance().keyboardAppearance = .dark
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!