iOS|iOS 导航栏的设置
在开发过程中难免会对导航栏进行设置,整理部分导航栏的设置,以备后用
+ (void)initialize {//appearance方法返回一个导航栏的外观对象//修改了这个外观对象,相当于修改了整个项目中的外观
UINavigationBar *navigationBar = [UINavigationBar appearance];
[navigationBar setBarTintColor:[UIColor colorWithRed:0.91 green:0.12 blue:0.31 alpha:1.0]];
[navigationBar setBackgroundImage:[UIImage imageNamed:@"backimg"] forBarMetrics:UIBarMetricsCompact];
navigationBar.translucent = NO;
//去掉导航栏的半透明状态(不去会有色差)
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[navigationBar setBarStyle:UIBarStyleDefault];
//
[navigationBar setBarTintColor:[UIColor redColor]];
[navigationBar setTintColor:[UIColor whiteColor]];
// 设置NavigationBarItem文字的颜色
NSShadow *shadow = [[NSShadow alloc]init];
[shadow setShadowOffset:CGSizeZero];
[navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName : [UIFont systemFontOfSize:18],NSShadowAttributeName : shadow}];
//修改所有UIBarButtonItem的外观
UIBarButtonItem *barButtonItem = [UIBarButtonItem appearance];
[barButtonItem setTintColor:[UIColor whiteColor]];
//self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
//如果想要统一定制返回按钮样式的话,可以重写如下方法//重写返回按钮
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
[super pushViewController:viewController animated:animated];
if (viewController.navigationItem.leftBarButtonItem ==nil && self.viewControllers.count >1) {viewController.navigationItem.leftBarButtonItem = [self creatBackButton];
self.interactivePopGestureRecognizer.delegate = (id)self;
【iOS|iOS 导航栏的设置】}
}
-(UIBarButtonItem *)creatBackButton
{
return [[UIBarButtonItem alloc]initWithImage: [UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(popSelf)];
}
-(void)popSelf
{
[self popViewControllerAnimated:YES];
}
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- IDEA|IDEA 创建工程
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- Android超简单实现沉浸式状态栏
- www和https://又被Chrome地址栏隐藏了
- 接口|axios接口报错-参数类型错误解决