iOS 7 UINavigationbar setTranslucent:没有崩溃的应用程序

use*_*249 8 iphone objective-c uinavigationbar ios ios7

我有一个UINavigationBar,它在app delegate类中设置了背景图像,所以你可以想象为什么我不喜欢Navigationbar是半透明的.我相信这是罪魁祸首:http://imgur.com/v3e0NIo

无论如何,当我把这行代码:

[[UINavigationBar appearance] setTranslucent:NO];
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate中遇到此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, B for appearance setter, _installAppearanceSwizzlesForSetter:'
Run Code Online (Sandbox Code Playgroud)

即使我试图在每个类中单独使每个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];
Run Code Online (Sandbox Code Playgroud)

即使我将UIViewController的背景设为黑色,白色条仍然存在..我现在高度怀疑透明度是我的问题!

Kyl*_*law 5

这个并将它放在viewdidload每个viewcontrollers类中:

    self.navigationController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)


小智 0

如果您使用 Interface Builder,您可以从中禁用半透明

Xib 文件 -> 属性检查器 -> 模拟指标并将顶部栏属性设置为不透明

或者尝试

self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

或者或者或者检查这篇文章 /sf/answers/1339010501/