我正在使用导航控制器,我将样式设置为:
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的程序时,导航控制器看起来像是在白色背景之上,而不是我的背景.当我向左或向右推动控制器时,我的所有视图(当前视图)都会移动到顶部,与导航栏的大小完全相同.在那里我可以通过导航控制器栏看到我的背景.有任何想法吗?当我的barStyle设置为不透明时,一切看起来都很好.我在考虑将我的视图框设置为负"y"值,但我认为应该采用更优雅的方式.
我有一个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的背景设为黑色,白色条仍然存在..我现在高度怀疑透明度是我的问题!