Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the UIKeyboard background color programmatically

Is there any way to get the UIKeyboard background color? I am putting an accessory view on top of my UIKeyboard and is trying to match its color with the keyboard background color. But, it seems, different types of keyboard has different background colors. Please see below screenshots for default and email keyboard.

Is there any way, we can find out the background color of the keyboard programmatically so that the color of the accessoryView could be changed.

UIKeyboardTypeEmailAddress

UIKeyboardTypeDefault

like image 435
Abhinav Avatar asked May 23 '14 04:05

Abhinav


2 Answers

Swift 5

You can use an input view and it matches the keyboard style.

let textView = UITextView()
let frame = CGRect(x: 0, y: 0, width: 0, height: 40)
textView.inputAccessoryView = UIInputView(frame: frame, inputViewStyle: .keyboard)
like image 102
vauxhall Avatar answered Oct 10 '22 21:10

vauxhall


You could do something like this:

UIKeyboardAppearance currentAppearance = yourTextView.keyboardAppearance;
if (currentAppearance == UIKeyboardAppearanceDark) {
    // dark
}
else if (currentAppearance == UIKeyboardAppearanceDefault) {
    // default
}
else if (currentAppearance == UIKeyboardAppearanceLight) {
    // light
}
like image 25
Logan Avatar answered Oct 10 '22 23:10

Logan