iOS小技能:去掉/新增导航栏黑边(iOS13适配)
“我正在参加「掘金·启航计划」”
引言
背景: 去掉导航栏下边的黑边在iOS15失效
原因:必须使用iOS13之后的APIUINavigationBarAppearance
设置才能生效
bash
UIKIT_EXTERN API_AVAILABLE(ios(13.0), tvos(13.0)) NS_SWIFT_UI_ACTOR
@interface UINavigationBarAppearance : UIBarAppearance
I 导航栏的黑边设置
1.1 去掉导航栏下边的黑边(iOS15适配)
iOS15之前:[self.navigationBar setShadowImage:[[UIImage alloc] init]];
```objectivec [vc.navigationController.navigationBar setBackgroundImage:[ImageTools createImageWithColor: [UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
```
iOS15之后 ```objectivec
if(@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
//去掉透明后导航栏下边的黑边
appearance.shadowImage =[[UIImage alloc] init];
appearance.shadowColor= UIColor.clearColor;
navigationBar.standardAppearance = appearance;
navigationBar.scrollEdgeAppearance = appearance;
}
```
1.2 设置导航栏下边的黑边(iOS13适配)
```objectivec
// 设置导航栏下边的黑边 + (void)setupnavigationBar:(UIViewController*)vc{
if (@available(iOS 13.0, *)) {
UINavigationBar *navigationBar = vc.navigationController.navigationBar;
UINavigationBarAppearance *appearance =navigationBar.standardAppearance;
appearance.shadowImage =[UIImage createImageWithColor:k_tableView_Line];
appearance.shadowColor=k_tableView_Line;
navigationBar.standardAppearance = appearance;
navigationBar.scrollEdgeAppearance = appearance;
} else {
// Fallback on earlier versions
UINavigationBar *navigationBar = vc.navigationController.navigationBar;
[navigationBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; //此处使底部线条颜色为红色
// [navigationBar setShadowImage:[UIImage createImageWithColor:[UIColor redColor]]];
[navigationBar setShadowImage:[UIImage createImageWithColor:k_tableView_Line]];
}
}
```
II 去掉TabBar的顶部黑线
-
setupshadowColor ```objectivec
-
(void)setupshadowColor{
UIView * tmpView = self; tmpView.layer.shadowColor = [UIColor blackColor].CGColor;//设置阴影的颜色 tmpView.layer.shadowOpacity = 0.08;//设置阴影的透明度 tmpView.layer.shadowOffset = CGSizeMake(kAdjustRatio(0), kAdjustRatio(-5));//设置阴影的偏移量,阴影的大小,x往右和y往下是正 tmpView.layer.shadowRadius = kAdjustRatio(5);//设置阴影的圆角,//阴影的扩散范围,相当于blur radius,也是shadow的渐变距离,从外围开始,往里渐变shadowRadius距离
//去掉TabBar的顶部黑线
[self setBackgroundImage:[UIImage createImageWithColor:[UIColor clearColor]]];
[self setShadowImage:[UIImage createImageWithColor:[UIColor clearColor]]];
}
```
see also
iOS小技能:自定义导航栏,设置全局导航条外观。(iOS15适配) http://blog.csdn.net/z929118967/article/details/104276156
- iOS小技能:UITableView的适配 (iOS10/iOS14/iOS16.0)
- iOS小技能:和uni-app、unity的融合方案
- iOS小技能:iOS15崩溃排查技巧(symbolicatecrash符号化分析问题、导出和隐藏符号)
- iOS小技能:【intercept the HTTP/HTTPS requests 】利用NSURLProtocol 拦截请求
- iOS小技能: tweak 集成CocoaAsyncSocket(建连、断开、重连、心跳、通用请求)
- iOS小技能:iOS13 证件扫描 & 文字识别API
- iOS小技能:集成下拉刷新控件 & 实现无感知上拉加载更多
- iOS小技能:代码触发button的点击事件、快速找到按钮action方法
- iOS小技能:拨号、发邮件、短信、应用间跳转
- iOS小技能:链式编程在iOS开发中的应用
- iOS小技能:iOS14 读取用户剪切板数据弹出提示的兼容方案
- iOS小技能:因境外IP无法访问导致 App 被拒的解决方案
- iOS小技能:RSA签名、验签、加密、解密的原理
- iOS小技能:Xcode14新特性(适配)
- iOS小技能:Socket基础知识
- iOS小技能:SKU视图搭建
- iOS小技能: 日历的使用(案例:两个时间的比较、获取最近30天的数据)
- iOS小技能:1. iOS 实现json数据提交 2. 对同一个URL的多次请求进行数据缓存 3. 检查网络状态
- iOS小技能:使用正则表达式对聊天记录的关键词进行监控
- iOS小技能:去掉/新增导航栏黑边(iOS13适配)