iphone - iOS 7 UINavigationbar setTranslucent : NO crashes app

标签 iphone ios objective-c ios7 uinavigationbar

<分区>

我有一个 UINavigationBar,它在应用程序委托(delegate)类中设置了背景图像,因此您可以想象为什么我不希望 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 的背景设为黑色,白色条仍然存在。我现在非常怀疑透明度是我的问题!

最佳答案

将其放入每个 View Controller 类的 viewdidload 中:

    self.navigationController.navigationBar.translucent = NO;

关于iphone - iOS 7 UINavigationbar setTranslucent : NO crashes app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19348297/

相关文章:

php - 使用 Paypal 的市场

iphone - 带有工厂方法的 Objective C 类继承

iPhone如何检查手机是否可以使用 native 邮件应用程序发送/接收邮件?

ios - 无法传递 UIVewController 的实例 - iOS

iphone - 通过 UIViewController 以编程方式实现 UIView

iphone - NSDecimalNumber 和从末尾弹出数字

ios - 此代码是否遵循标准的 Objective-C 和 MVC 约定?

ios - 如何缓存 NSUrlSession 响应数据

iphone - 第二次解析调用导致 NSXMLParser 内存泄漏

iphone - 不兼容的指针类型将类发送到类型 id fbsessiondelegate 的参数