在嘗試如何將NavigationController 半透明,原本嘗試了

self.navigationController.navigationBar.alpha = 0.5;

,確實出現半透明沒錯,但是連barItem都會跟著半透明,經過一番嘗試與研究發現,需設定Translucent為Yes,以及TintColor,

最重要的是BarItem要放在最後,再對他進行設定,這樣就能夠實現半透明NavigationBar並且保留原本的按鈕顏色(不會被半透明),就像是Photo App上方一樣。

 

Objective-C Code:

    UINavigationBar *topBar = self.navigationController.navigationBar;

    [topBar setTranslucent:YES];

    [topBar setTintColor:[UIColorcolorWithRed:0.5 green:0.5 blue:0.5 alpha:0]];

    [self.navigationItem.rightBarButtonItemsetTintColor:[UIColorcolorWithRed:0 green:0 blue:0 alpha:1]];

 

# 2014/11/07 更新:

[topBar setBarStyle:UIBarStyleBlackTranslucent];

後來發現只要加這行就可以了,其它的都可以刪除

 

參考資料:

http://stackoverflow.com/questions/23555323/blur-uinavigationbar-like-the-photo-app

http://stackoverflow.com/questions/8221581/custom-back-button-on-navigation-bar

http://stackoverflow.com/questions/1449339/how-do-i-change-the-title-of-the-back-button-on-a-navigation-bar

arrow
arrow
    全站熱搜

    小賢 發表在 痞客邦 留言(0) 人氣()