Set UIKeyboardAppearance across the whole app

狂风中的少年 提交于 2019-12-07 06:02:55

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19030619/set-uikeyboardappearance-across-the-whole-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!