为什么我的应用程序在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中执行此操作吗?
Everything Compiles,但是App在控制台中崩溃了这个错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:
答案 0 :(得分:1)
UIAppearance
个方法([SomeClass appearance]
)会对该类型的所有控件生效。您只需要声明一次,然后创建的任何新控件都将采用该样式。
但是,并非所有属性都可以与UIAppearance
一起使用。半透明就是其中之一,因此对setTranslucent:
的调用是导致崩溃的原因。如果您查看UINavigationBar
标题,则可以自行查看 - translucent
没有UI_APPEARANCE_SELECTOR
注释。您必须在特定导航栏实例上设置半透明度。
答案 1 :(得分:0)
看起来您正在使用最新的Xcode& iOS(5& 7)但你试图在iOS版本较低的模拟器上运行它,即6.x。
崩溃的主要原因可能是setBarTintColor,这在7.0之前的iOS版本中不存在
我希望有所帮助。