iOS 7中设置UINavigationBar的setTranslucent:NO会导致应用程序崩溃

8

我有一个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的背景设置为黑色,白色的条仍然存在..我现在非常怀疑透明度是我的问题所在!

我宁愿不制作自定义NavigationBar。 - user1064249
2个回答

5

尝试将以下代码放置在每个视图控制器类的viewdidload中:

    self.navigationController.navigationBar.translucent = NO;

1
我尝试过了,但白色仍然显示。这让我想到半透明是否真的是我的问题。 - user1064249

0
如果您使用Interface Builder,可以从中禁用透明度。
Xib文件->属性检查器->模拟指标,将顶部栏属性设置为不透明。
或者尝试
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
或者查看此帖子 https://dev59.com/sWQn5IYBdhLWcg3wETk5#19128721

我正在使用故事板 :( - user1064249
我尝试了UIBarStyleBlackOpaque,虽然白色的电池和时间看起来很好,但是白色的条仍然存在。故事板选项不可用,因为我正在使用导航控制器。 - user1064249

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接