iOS開發--一些UINavigationBar屬性的設置

1.iOS7以後 要想改變navigationbar的顏色 能夠這樣子改app

self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#3A3A3A" alpha:1.0f];框架

默認帶有必定透明效果,可使用如下方法去除系統效果
字體

[self.navigationController.navigationBar setTranslucent:NO];spa


改變navigationbar的顏色代理

2.改變UINavigationBar導航條標題顏色和字體code

iOS 5 之後 UINavigationController 能夠 改變UINavigationBar導航條標題顏色和字體orm

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], NSForegroundColorAttributeName,[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1],NSShadowAttributeName,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], NSShadowAttributeName,[UIFont fontWithName:@"Arial-Bold" size:0.0], NSFontAttributeName,nil]];圖片


改變UINavigationBar導航條標題顏色和字體ci

其中 NSForegroundColorAttributeName和NSFontAttributeName 屬性是文字顏色和字體unicode

3.改變狀態欄的顏色

公司項目須要將狀態欄的文字顏色設置爲白色,如下方法便可

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

改變後須要及時刷新的調用

[viewController setNeedsStatusBarAppearanceUpdate];

若是沒有效果,須要在plist文件裏設置

View controller-based status bar appearance  = NO

info.plist中 View controller-based status bar appearance這個屬性 View controller-based status bar appearance =NO 這個設置爲:View Controller 不對status Bar 顯示進行操做

4.在某些頁面控制navigationbar不顯示

在項目中有時候會遇到在有些頁面想隱藏navgationbar的狀況,只要像這樣寫就能夠了


隱藏導航條代碼示例

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

[self.navigationController setNavigationBarHidden:YES animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated {

[super viewWillDisappear:animated];

[self.navigationController setNavigationBarHidden:NO animated:animated];

}

5.圖片選擇器調用時候有關導航條的問題

有時候調用系統相冊的時候,若是咱們總體導航條背景顏色是經過一張圖片進行加載的話 那麼相冊調用出來後,導航條的顏色也是會加載這張圖片的,可是若是整條導航填顏色是經過顏色色值來加載的話,這時候系統相冊調用出來的顏色就是系統默認的,致使白色導航條,白色文字就會顯示不出來,從而影響用戶體驗;還有一種狀況是,調用系統相冊以後,導航條上的文字,和取消按鈕都是顯示的英文,跟咱們總體風格格格不入,所以咱們須要重寫相冊導航條上的內容、圖片和文字以及文字顏色.

(1)若是總體導航條是按照色值來的,修改方法


實現UINavigationDelegate方法

// 實現navigationController的代理

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

{

viewController.navigationController.navigationBar.barTintColor = MainAppColor;

[viewController.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica Neue" size:19.0f], NSFontAttributeName,nil]];

viewController.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];

}

(2)若是顯示出來的是英文 咱們想改爲中文的


代理方法實現

在調用系統相冊、相機發現是英文的系統相簿界面後標題顯示「photos」,可是手機語言已經設置顯示中文,在info.plist設置解決問題  info.plist裏面添加Localized resources can be mixed YES 表示是否容許應用程序獲取框架庫內語言。


info.plist中的設置

相關文章
相關標籤/搜索