iosiphoneobjective-ccocoa-touchuikeyboard

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


Solution

  • You could do something like this:

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