如何在Xcode 26(iOS 26 SDK)中将UITabBarController还原为iOS 18及更早版本的外观?
如何在Xcode 26(iOS 26 SDK)中将UITabBarController还原为iOS 18及更早版本的外观?
我前段时间升级到Xcode 26后也碰到了一模一样的问题——系统默认的Liquid Glass风格TabBar完全打乱了我们跨平台的设计规范,而且hidesBottomBarWhenPushed还失效了,折腾了好一阵才找到可行的方案,分享给你:
一、目前官方还没有直接的「退回到旧样式」API
iOS 26刚推出Liquid Glass设计,苹果暂时没提供开关让开发者直接禁用这个新外观,所以只能靠手动定制来模拟旧样式。
二、最稳妥的方案:完全自定义TabBar
这种方式虽然需要写点额外代码,但能100%还原iOS 18及更早的TabBar样式,还能彻底解决hidesBottomBarWhenPushed的问题:
- 隐藏系统原生TabBar:在你的UITabBarController子类的
viewDidLoad里把系统TabBar藏起来override func viewDidLoad() { super.viewDidLoad() tabBar.isHidden = true // 添加自定义TabBar let customTabBar = CustomTabBar(frame: CGRect(x: 0, y: view.bounds.height - 83, width: view.bounds.width, height: 83)) customTabBar.delegate = self view.addSubview(customTabBar) view.bringSubviewToFront(customTabBar) } - 实现自定义TabBar类:用UIView做容器,添加几个UIButton作为Tab项,自己控制选中/未选中的图标、文字样式,背景色用iOS 18之前的半透明或纯色(比如
UIColor.systemBackground.withAlphaComponent(0.8)) - 处理页面切换逻辑:给自定义TabBar加代理方法,点击按钮时切换TabBarController的
selectedIndex - 修复push隐藏问题:给导航控制器设置代理,监听页面push/pop事件,手动显示/隐藏自定义TabBar:
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { let shouldHide = viewController.hidesBottomBarWhenPushed customTabBar.isHidden = shouldHide // 调整子控制器的安全区,避免内容被TabBar遮挡 viewControllers?.forEach { vc in vc.additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: shouldHide ? 0 : 83, right: 0) } }
三、尝试修改系统TabBar属性(不一定完全生效)
如果不想完全自定义,可以试试强制覆盖系统的Liquid Glass样式,但部分属性可能因为系统优先级高而不生效,适合快速测试:
// 重置TabBar的外观配置,去掉模糊效果 let tabBarAppearance = UITabBarAppearance() tabBarAppearance.backgroundColor = UIColor.systemBackground.withAlphaComponent(0.8) tabBarAppearance.shadowImage = UIImage() tabBarAppearance.shadowColor = nil // 配置Tab项的文字和图标样式 let itemAppearance = UITabBarItemAppearance() itemAppearance.normal.iconColor = .secondaryLabel itemAppearance.selected.iconColor = .tintColor itemAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.secondaryLabel] itemAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.tintColor] tabBarAppearance.stackedLayoutAppearance = itemAppearance tabBar.standardAppearance = tabBarAppearance tabBar.scrollEdgeAppearance = tabBarAppearance // 关闭半透明,可能有助于覆盖新样式 tabBar.isTranslucent = false
四、社区现状
目前不少升级到Xcode 26的开发者都反馈了这个问题,大家普遍猜测苹果会在后续的Beta版本中添加官方的opt-out接口,所以你可以多关注iOS 26的开发者文档更新。如果设计团队要求严格,还是推荐用完全自定义的方案,既能保证跨平台UI一致,也不受系统更新的影响。
内容来源于stack exchange
相关产品推荐
相关产品推荐

