19

With iOS7, the protocol UITextInputTraits gets new values for the enum UIKeyboardAppearance. In particular I'm interested in changing the keyboardAppearance to UIKeyboardAppearanceDark in order to match the current app dark design.

I first looked into the Info.plist but it seems that there isn't a key in that allows you to globally set this property.

My second thought was to use the UIAppearance but unfortunately the keyboardAppearance doesn't have the UI_APPEARANCE_SELECTOR decorator. But for some reason this code:

[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];

works on iOS7, but crashes in iOS6.

Even more strangely the following code:

[[UITextView appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];

doesn't work in iOS7 nor iOS6.

A good idea can be to create a subclass of both UITextField & UITextView but in this way this doesn't work for example in UISearchBar.

I don't want to create a category because I don't want to sort-of-override the implementation of Apple classes and probably not been future proof.

Any one have ever dealt with this?

Steph Sharp
  • 11,462
  • 5
  • 44
  • 81
Luca Bernardi
  • 4,191
  • 2
  • 31
  • 39

1 Answers1

4

Use this control https://github.com/hackiftekhar/IQKeyboardManager

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[IQKeyboardManager sharedManager] setOverrideKeyboardAppearance:YES];
    [[IQKeyboardManager sharedManager] setKeyboardAppearance:UIKeyboardAppearanceDark];
    return YES;
}

It is mainly used to manage the distance between keyboard & textField but your issue can also be resolved via this great library.

Mohd Iftekhar Qurashi
  • 2,385
  • 3
  • 32
  • 44
  • Thanks for sharing, this is a good one, worked for me as I wanted to change the appearance of my apps keyboard. In fact, earlier I tried it by writing my own Keyboard by modifying a UIView with an image pasted on it, but it was like reinventing the wheel. – chathuram Apr 14 '14 at 15:46