2012-07-31 187 views
0

我已經在Photoshop 一個簡單的設計,當我試圖把它在Xcode中我遇到了一些問題,導航欄透明圖像

我用這個代碼來改變UINavigationBar的背景圖像(PNG透明圖像) :

UINavigationBar *navBar = [[self navigationController]navigationBar]; 
[navBar setBackgroundImage[UIImageimageNamed:@"navBar2.png"]forBarMetrics:UIBarMetricsDefault] 

一切工作正常,但問題是,圖像出現在navigationBar沒有透明度。

請別人幫我解決透明度問題我到處搜索沒有任何滿意的答案
注意!我使用IOS 5

回答

3

您可以嘗試將導航欄設置爲半透明。

[navBar setTranslucent: YES]; 
+0

我試圖使用黑色半透明樣式,它顯示透明度......但現在我的UITableView位於UINavigationBar下方,請參閱下圖http://www.monsterup.com/image.php?url=upload/1343761351853.png – 2012-07-31 19:04:36

+0

只需在故事板或以編程方式將其下移。 – Regan 2012-07-31 19:08:17

+0

不完全是我想要的,但它應該解決我的問題,謝謝我的朋友 – 2012-07-31 19:11:46

0

你有沒有在你的故事板?嘗試將導航欄的樣式改爲黑色半透明。

+0

是的,我有它在故事板 我試圖用黑色半透明式的,它顯示了透明度... 但現在的UITableView是下方的UINavigationBar的看到的畫面波紋管 http://www.monsterup.com /image.php?url=upload/1343761351853.png – 2012-07-31 19:02:54

+0

是不是你想要的?在導航欄下面放置背景?如果不是那麼最簡單的方法就是在photoshop中製作一個帶背景的導航欄,並將其設置爲xcode中的不透明 – aforaudrey 2012-07-31 19:40:23

0

你可以做的是設置navigationController視圖的背景顏色與主視圖的backgrouond顏色相同。

//Set your view's background color  
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"view_background"]]]; 

//Set your custom image for the navigationController 
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"navigation_bar_image"] forBarMetrics:UIBarMetricsDefault]; 

//And then set the background color of the navigationController the same as the one of the view 
[self.navigationController.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"view_background"]]]; 
0
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 
[self.navigationBar setShadowImage:[UIImage new]]; 
[self.navigationBar setTranslucent:YES]; 

並確保您設置色調顏色爲默認值。