Getting the UIKeyboard background color programmatically

Abhinav picture Abhinav · May 23, 2014 · Viewed 8.2k times · Source

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

Answer

vauxhall picture vauxhall · Jun 29, 2019

Swift 5

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

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