iOS开发--一些UINavigationBar属性的设置

1.iOS7之后 要想改变navigationbar的颜色 可以这样子改

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

默认带有一定透明效果,可以使用以下方法去除系统效果

[self.navigationController.navigationBar setTranslucent:NO];

2.改变UINavigationBar导航条标题颜色和字体

[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]];

其中 NSForegroundColorAttributeName和NSFontAttributeName 属性是文字颜色和字体

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];

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值