Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the keyboardAppearence for the whole app

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?

like image 945
Luca Bernardi Avatar asked Oct 28 '13 17:10

Luca Bernardi


People also ask

How do I get the full keyboard back on my iPhone?

Go to Settings > Accessibility > Keyboards, tap Full Keyboard Access, then turn on Full Keyboard Access.


1 Answers

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.

like image 53
Mohd Iftekhar Qurashi Avatar answered Oct 09 '22 02:10

Mohd Iftekhar Qurashi