2014-04-05 94 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