How to change keyboard background color in iOS?

2019-01-10 20:16发布

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

4条回答
Summer. ? 凉城
2楼-- · 2019-01-10 20:48

To change it globally, you can use appearance proxy in AppDelegate... I've tested it in iOS 8, Swift:

UITextField.appearance().keyboardAppearance = .Dark
查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-10 20:54

Updating to swift 3.0

let textFieldAppearance = UITextField.appearance() textFieldAppearance.keyboardAppearance = .dark //.default//.light//.alert

查看更多
叛逆
4楼-- · 2019-01-10 20:59

For the dark background use

    mytextfield.keyboardAppearance = UIKeyboardAppearanceAlert;

Read to find more information about UITextInputTraits (use UIKeyboardAppearanceDark at iOs 7+).

查看更多
Ridiculous、
5楼-- · 2019-01-10 21:09

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);
查看更多
登录 后发表回答