//修改导航栏字体颜色及字体大小
[self.navigationController.navigationBar setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName : [UIFont systemFontOfSize:18] }];
//设置导航栏背景颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
//设置导航栏无透明背景颜色
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"colorpic"] forBarMetrics:UIBarMetricsDefault]; //照片为对应颜色的随意大小的背景图,这样不会有透明度
//设置导航栏没有边界线
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
//当设置导航栏没有任何颜色时:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//设置导航栏透明
self.navigationController.navigationBar.translucent = YES;
//要隐藏导航栏时
[self.navigationController setNavigationBarHidden:YES animated:NO];
//当我们隐藏导航栏时,往往会出现状态栏statusBar未能被试图覆盖,导致试图最上方有一长条。所以要设置当前控制器:
self.automaticallyAdjustsScrollViewInsets = NO;//来取消导航栏对顶端的影响。
//设置导航栏样式,UIBarStyleDefault是默认样式,UIBarStyleBlack是黑色不透明。UIBarStyleBlackOpaque和UIBarStyleBlackTranslucent这两个已经废弃了
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
//开启导航栏左滑后退
self.navigationController.interactivePopGestureRecognizer.delegate = self;
//若果想在某个界面禁止左滑
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
- (void)viewWillDisappear:(BOOL)animated {
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
iOS导航栏相关属性以及常见需求
最新推荐文章于 2024-04-23 23:18:43 发布