我有一个UINavigationBar,在应用程序委托类中设置了背景图像,所以您可以想象为什么我不希望Navigationbar是半透明的。我相信这就是罪魁祸首:http://imgur.com/v3e0NIo
无论如何,当我放置这行代码:
[[UINavigationBar appearance] setTranslucent:NO];
在我的AppDelegate中,我遇到了这个错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, B for appearance setter, _installAppearanceSwizzlesForSetter:'
即使我试图在每个类中单独使每个UINavigationbar不透明,仍然有一个愚蠢的白色条在图像中!尽管没有错误抛出,但这让我想知道代码是否有效,或者透明度不是我的问题?
谢谢!
编辑:
这是我在AppDelegate中使用的代码,用于为NavBar创建自定义背景:
[[UINavigationBar appearance] setTitleTextAttributes: @{
UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeTextShadowColor: [UIColor blackColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:@"Code-Bold" size:23.0f]
}];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
UIImage *navBarImage = [[UIImage imageNamed:@"menubar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 15, 5, 15)];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
即使我将UIViewController的背景设置为黑色,白色的条仍然存在..我现在非常怀疑透明度是我的问题所在!