2014-04-05 95 views
6

我想让我的导航栏变为100%透明,这样UINavigationButtonItems只能看到,背景(通常是白色)应该显示背景图像。UINavigationController透明度?

我试图

HomeNavigationController *navBar = [[HomeNavigationController alloc] initWithRootViewController:self.myViewController]; 
[navBar.navigationBar setBarTintColor:[UIColor clearColor]]; 
    [navBar.navigationBar setTranslucent:YES]; 

虽然没有出现工作。

编辑:

使用

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] 
        forBarMetrics:UIBarMetricsDefault]; 
self.navigationController.navigationBar.shadowImage = [UIImage new]; 
self.navigationController.navigationBar.translucent = YES; 
self.navigationController.view.backgroundColor = [UIColor clearColor]; 

我可以看到,它的工作如预期,但该项目现在也看不到的。


FINALEDIT:阿上面的代码不工作,只是确保你不会不先试应用任何其他更改外观!

,实际上做什么打算代码:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] 
                forBarMetrics:UIBarMetricsDefault]; 

或者你可以设置一个透明的形象,但是这更有意义。如果您不需要代表边界的线,则需要原始编辑中显示的其余代码。

+0

可以尝试[navBar.navigationBar setTintColor:的UIColor colorWithWhite:1.0阿尔法:0.0]; – user2277872

+1

看到这个:http://stackoverflow.com/questions/21850622/transparent-uinavigationbar/21850947#21850947,也许可以帮助你。 –

+1

如果你需要你的UINavigationBar是完全透明的,那么为什么不把它完全隐藏起来,并使用自定义的'UIButtons'而不是'UIBarButtonItems'? UINavigationBars,UITabBars和UIToolbars的外观随iOS 7的改变而变得更加困难,并且可能不建议对它们的透明度进行修改。 –

回答

6

有一个窍门。 只需将透明图像设置为导航栏背景即可。

UIImage *fakeImage = [UIImage imageNamed:@"transparentImage"]; 
[navigationBar setBackgroundImage:fakeImage forBarMetrics:UIBarMetricsDefault]; 

OR

[navigationBar setBackgroundImage:[UIImage new] 
        forBarMetrics:UIBarMetricsDefault]; 
+1

您还需要以相同的方式将阴影图​​像设置为空的“UIImage”。 – voidref