Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UIKeyboardAppearance across the whole app

Is there a useful property in a cocoa-touch project that would allow setting the one-and-only consistent style of keyboard appearance throughout the app? Say I want UIKeyboardAppearanceAlert on all the textFields and textViews I have in my app without directly modifying anything. Is is possible?

like image 419
Sergey Grischyov Avatar asked Sep 26 '13 14:09

Sergey Grischyov


1 Answers

No, it isn't possible. The keyboardAppearance is part of the UITextInputTraits protocol and is not marked as a UIAppearance method. If it was you could do something like:

[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceAlert];

You can identify methods that can be used with the appearance proxy by looking at the docs or, from within your code, at the UIKit headers (command-click on a method and it will take you to the header.

For example, in UINavigationBar.h, you can see this:

@property(nonatomic,retain) UIColor *barTintColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;  // default is nil

The marker UI_APPEARANCE_SELECTOR means that this property can be used on the appearance proxy. It isn't present on keyboardAppearance, and it doesn't look like any keys in the info.plist allow you to define an application-wide appearance.

Your best bet is to subclass textfield and textview and use those subclasses everywhere.

like image 80
jrturton Avatar answered Nov 12 '22 09:11

jrturton