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中的设置

相关文章
相关标签/搜索