iOS15-UITableView多了白条,导航栏和Tabbar变成白色和标题变黑处理--总结属性变化和原来基本的导航栏属性总结记录(看到就更新)
先看情况:
查资料发现iOS15 中
UITableView
新加了一个属性:sectionHeaderTopPadding
,automaticDimension
,就会导致顶部多出一条空白。1 2 3 4 5 6 7 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath { //加这里 if ( @available (iOS 15.0, *)) { self .tableView.sectionHeaderTopPadding = 0; } } |
1.iOS15更新之后 导航条突然就白了?一招教你变回来~
1.导航栏变白
2.导航栏字体变黑
3.tabbar
OC:
1.导航栏
BaseNavigationController的viewDidLoad方法里添加:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | - ( void )viewDidLoad { [ super viewDidLoad]; if ( @available (iOS 13.0, *)) { UINavigationBarAppearance *appearance = [UINavigationBarAppearance new ]; [appearance configureWithOpaqueBackground]; // 改变导航栏的颜色 appearance.backgroundColor = self .configuration.barTineColor; // 改变导航栏的标题颜色 appearance.titleTextAttributes = @{ NSFontAttributeName :[UIFont systemFontOfSize:18], NSForegroundColorAttributeName :[UIColor whiteColor]}; //导航栏包含状态栏 阴影线颜色背景色设置 appearance.shadowColor = self .configuration.barTineColor; // 静止样式 self .navigationBar.standardAppearance = appearance; // 滚动样式 self .navigationBar.scrollEdgeAppearance = self .navigationBar.standardAppearance; } } |
2.Tabbar
BaseTabBarController 的 viewDidLoad方法里添加:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | - ( void )viewDidLoad { [ super viewDidLoad]; if ( @available (iOS 13.0, *)) { UITabBarAppearance *appearance = [UITabBarAppearance new ]; [appearance configureWithOpaqueBackground]; appearance.backgroundColor = [UIColor hexColor:0x111423]; self .tabBar.standardAppearance = appearance; /// 这里有点区别。导航栏是iOS13开始。这里是iOS15才有的 if ( @available (iOS 15.0, *)) { self .tabBar.scrollEdgeAppearance = self .tabBar.standardAppearance; } } } |
Swift:
1.导航栏
1 2 3 4 5 6 7 8 9 10 11 12 13 | if #available(iOS 13.0, *) { let app = UINavigationBarAppearance() app.configureWithOpaqueBackground() // 重置背景和阴影颜色 app.backgroundEffect = nil //这里设置透明或者不透明 app.titleTextAttributes = [ NSAttributedString .Key.font: UIFont.systemFont(ofSize: 18), NSAttributedString .Key.foregroundColor: UIColor.white ] app.backgroundColor = .clear // 设置导航栏背景色 app.shadowColor = nil UINavigationBar.appearance().scrollEdgeAppearance = nil // 带scroll滑动的页面 UINavigationBar.appearance().standardAppearance = app // 常规页面。描述导航栏以标准高度 } |
2.Tabbar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // tabBar if #available(iOS 13.0, *) { let itemAppearance = UITabBarItemAppearance() itemAppearance.normal.titleTextAttributes = [.foregroundColor: NorMal_Color ?? .green] itemAppearance.selected.titleTextAttributes = [.foregroundColor: Selected_Color ?? .orange] let appearance = UITabBarAppearance() appearance.stackedLayoutAppearance = itemAppearance appearance.configureWithOpaqueBackground() appearance.backgroundColor = .white tabBarController?.tabBar.standardAppearance = appearance if #available(iOS 15.0, *) { tabBarController?.tabBar.scrollEdgeAppearance = tabBarController?.tabBar.standardAppearance } else { // Fallback on earlier versions } } |
参考:https://baijiahao.baidu.com/s?id=1711749740139600655&wfr=spider&for=pc
造成这个原因是什么呐?
答: 两个因素.
-
scrollEdgeAppearance 属性
-
iOS15 强制适用于所有导航器
当导航控制器包含导航栏和滚动视图时,滚动视图的部分内容将显示在导航栏下方。如果滚动内容的边缘到达该栏,UIKit将在此属性中应用外观设置。如果此属性的值为nil,UIKit将使用standardAppearance属性中的设置,并修改为使用透明背景。如果没有导航控制器管理您的导航栏,UIKit将忽略此属性,并使用导航栏的标准外观。在使用iOS 14或更低版本的应用程序上运行时,此属性适用于标题较大的导航栏。在iOS 15中,此属性适用于所有导航栏。
如何解决.
@NSCopying var scrollEdgeAppearance: UINavigationBarAppearance? { get set }
我们只需要按照UIKit 的最新改动进行适配就好.如下上:
1 | <a id = "cb_post_title_url" class = "postTitle2 vertical-middle" style= "font-size: 2em; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif" href= "https://www.cnblogs.com/jaly2012/p/5929571.html" >iOS 导航栏的属性设置</a> |

如果设置导航栏透明 ,也会无效。
原因:新的导航栏 在加入 large 模式之后 apple 会对普通模式的 nav 的 _UIbarBackground 进行一次 alpha = 1 的设置。
我们直接改变其 subview 的 alpha 就好了。
解决方法:
3. backgroundImage:背景图片
4. backgroundImageContentMode : 渲染 backgroundImage 时使用的内容模式。 默认为 UIViewContentModeScaleToFill 。
5. shadowColor:底部分割线阴影颜色
6. shadowImage: 阴影图片
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | //新建一个导航栏 UINavigationBarAppearance *appearance = [UINavigationBarAppearance new ]; //导航栏包含状态栏重置背景和阴影颜色 [appearance configureWithOpaqueBackground]; //导航栏包含状态栏背景色设置 appearance.backgroundColor = [UIColor colorWithRed:95.0/255.0 green:177.0/255.0 blue:53.0/255.0 alpha:1.0]; //导航栏包含状态栏 阴影线颜色背景色设置 appearance.shadowColor = [UIColor colorWithRed:95.0/255.0 green:177.0/255.0 blue:53.0/255.0 alpha:1.0]; // 常规页面。描述导航栏以标准高度 self .navigationBar.standardAppearance = appearance; //导航栏包含状态栏带scroll滑动的页面 self .navigationBar.scrollEdgeAppearance = self .navigationBar.standardAppearance; //设置导航栏为不透明 self .navigationController.navigationBar.translucent = NO ;; //iOS7之后由于navigationBar.translucent默认是YES,原点在(0,0)点,当设置NO的时候,原点坐标在(0,64)点 //设置导航栏bar默认颜色 self .navigationController.navigationBar.barTintColor = [UIColor redColor]; //设置导航栏两侧控件颜色(文字颜色) self .navigationController.navigationBar.tintColor = [UIColor whiteColor]; //设置导航栏图片颜色做背景,没有图片iOS13前默认是透明状态 self .navigationController.navigationBar.shadowImage = [UIImage new ]; [ self .navigationController.navigationBar setBackgroundImage:[UIImage new ] forBarMetrics:UIBarMetricsDefault]; self .navigationController.navigationBar.subviews.firstObject.alpha = 0; ////2. backgroundColor:注意 这个属性在 backgroundImage 下(在某个界面单独设置导航栏颜色,直接使//用 backgroundColor 无效,被 backgroundImage 遮住了) //如果设置导航栏透明 ,也会无效。 //原因:新的导航栏 在加入 large 模式之后 apple 会对普通模式的 nav 的 _UIbarBackground 进行一次 alpha //= 1 的设置。 //我们直接改变其 subview 的 alpha 就好了。 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix