如何在 iOS 中更改键盘背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9728847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change keyboard background color in iOS?
提问by Matthieu Lucas
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).
我想知道如何在 iOS 中以编程方式更改键盘背景颜色?背景通常是灰色的,但我已经看到黑色背景(在字母后面)。
回答by A-Live
For the dark background use:
对于深色背景使用:
mytextfield.keyboardAppearance = UIKeyboardAppearanceAlert;
Read to find more information about UITextInputTraits(use UIKeyboardAppearanceDark
at iOS 7+).
阅读以了解有关UITextInputTraits 的更多信息(UIKeyboardAppearanceDark
在 iOS 7+ 上使用)。
回答by Soheil Jadidian
To change it globally, you can use appearance proxy in AppDelegate... I've tested it in iOS 8, Swift:
要全局更改它,您可以在 AppDelegate 中使用外观代理...我已经在 iOS 8、Swift 中对其进行了测试:
UITextField.appearance().keyboardAppearance = UIKeyboardAppearance.dark
回答by Mr. T
In iOS 7, UIKeyboardAppearanceAlert
is deprecated, so use this instead:
在 iOS 7 中,UIKeyboardAppearanceAlert
已弃用,因此请改用它:
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:
如果您需要同时支持早期的 iOS 和 iOS 7,并且您已经创建了必要的宏(根据https://stackoverflow.com/a/5337804/588253),您可以使用这个:
mytextfield.keyboardAppearance = (SYSTEM_VERSION_LESS_THAN(@"7.0") ? UIKeyboardAppearanceAlert : UIKeyboardAppearanceDark);
回答by Emmanouil Nicolas
Updating to swift 3.0
更新到 swift 3.0
let textFieldAppearance = UITextField.appearance()
textFieldAppearance.keyboardAppearance = .dark //.default//.light//.alert
let textFieldAppearance = UITextField.appearance()
textFieldAppearance.keyboardAppearance = .dark //.default//.light//.alert
回答by nambatee
回答by Dani G.
SWIFT 4+: in the AppDelegate
SWIFT 4+:在 AppDelegate 中
UITextField.appearance().keyboardAppearance = .dark
回答by Mike
Today just use myTextField.keyboardAppearance = .dark
今天只用 myTextField.keyboardAppearance = .dark
回答by Mussa Charles
Swift 5+ (TextView)
Swift 5+ (TextView)
textView.keyboardAppearance = .dark