当我在AppDelegate中添加它时,为什么我的应用程序总是崩溃?
// Change Global Style of the UINavigationBar
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:12.0/255.0 green:109.0/255.0 blue:216.0/255.0 alpha:1.0]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Chnage Global TabBar Color w/ Options
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor orangeColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:12.0/255.0 green:109.0/255.0 blue:216.0/255.0 alpha:1.0]];
[[UITabBar appearance] setTranslucent:NO];
我应该在每个VC中而不是AppDelegate中这样做吗?
一切都能编译,但是应用程序在控制台中崩溃并显示以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:
最佳答案
UIAppearance
方法([SomeClass appearance]
)对该类型的所有控件都起作用。您只需声明一次,然后创建的任何新控件都将采用该样式。
但是,并非所有属性都可以与UIAppearance
一起使用。半透明就是其中之一,因此对setTranslucent:
的调用是导致崩溃的原因。如果您查看UINavigationBar
header ,则可以自己看到-translucent
没有UI_APPEARANCE_SELECTOR
批注。您必须在特定的导航栏实例上设置透明度。
关于ios - AppDelegate中的全局 View 样式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21290363/