在我的应用程序中有一个UIWebView,问题在于我有一个UIAppearance,它修改了分段控件的外观,所以它修改了UIWebView文本字段输入附件视图中的分段控件,我希望它看起来正常,或者不要尝试修改它。这是当前的样子:
[[UISegmentedControl appearance] setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearanceWhenContainedIn:[MyViewController class], [MyOtherViewController class], nil] setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
您不需要列出所有的ViewController,只需列出顶级的即可。这也使得下面的技巧成为可能:创建一个'空的'UIViewController子类CustomizedViewController,除了作为一个子类外不做任何其他事情 - 然后从中派生你的代码而不是从UIViewController中派生(基本上用'CustomizedViewController'替换所有出现的'UIViewController',除非CustomizedViewController实际声明UIViewController为其超类)。
然后使用
[[UISegmentedControl appearanceWhenContainedIn:[CustomizedViewController class], nil] setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
好的,我终于能够想出一个解决方法。请查看我的评论,了解为什么那个答案对我无效。
简单重申一下,据我所知,创建键盘附件的iOS代码明确设置UIToolbar背景,因此您将无法获得UIAppearance背景设置,但您将获得UIBarButtonItem样式。结果是半样式视图,可能看起来很糟糕。幸运的是,我的设计师对于在这种特定情况下回退到默认样式感到满意。
所以,关键是找出如何使该视图不通过UIAppearance进行样式设置。我做的方法是替换这个:
id barButtonAppearanceProxy = [UIBarButtonItem appearance];
通过这个:
// wtf: Style any UIBarButtonItem associated with a UIViewController
id barButtonAppearanceProxy = [UIBarButtonItem appearanceWhenContainedIn:[UIViewController class], nil];