以编程方式获取UIKeyboard背景颜色

Abh*_*nav 7 iphone cocoa-touch objective-c uikeyboard ios

有没有办法获得UIKeyboard背景颜色?我正在将配件视图放在我的上方,UIKeyboard并尝试将其颜色与键盘背景颜色相匹配.但是,似乎不同类型的键盘具有不同的背景颜色.请参阅以下屏幕截图,了解默认和电子邮件键盘.

有什么办法,我们可以通过编程方式找出键盘的背景颜色,以便accessoryView可以改变颜色.

UIKeyboardTypeEmailAddress

UIKeyboardTypeDefault

Log*_*gan 5

你可以这样做:

UIKeyboardAppearance currentAppearance = yourTextView.keyboardAppearance;
if (currentAppearance == UIKeyboardAppearanceDark) {
    // dark
}
else if (currentAppearance == UIKeyboardAppearanceDefault) {
    // default
}
else if (currentAppearance == UIKeyboardAppearanceLight) {
    // light
}
Run Code Online (Sandbox Code Playgroud)


vau*_*all 5

斯威夫特 5

您可以使用输入视图,它与键盘样式相匹配。

let text = UITextView()
text.inputAccessoryView = UIInputView(frame: .init(x: 0, y: 0, width: 0, height: 40), inputViewStyle: .keyboard)
Run Code Online (Sandbox Code Playgroud)

  • 你知道如何在“UIInputView”中添加“UIToolbar”吗?如果我只是执行“uiInputView.addSubview(uiToolbar)”,则不会出现工具栏 (2认同)