UITabBar上方出现白色区域的原因及移除方法咨询
UITabBar上方白色区域的原因及解决方法
原因分析
你遇到的白色区域,本质是UITabBar的barTintColor默认背景层。当你设置isTranslucent = false时,barTintColor对应的背景层会显示在backgroundColor之上;你目前只配置了backgroundColor,未设置barTintColor,所以该层保持默认白色,从而出现这块区域。
切换到橙色背景的ShopViewController时白色区域消失,是因为该VC的视图默认延伸到TabBar下方,橙色背景覆盖了TabBar的barTintColor层,视觉上让白色区域“消失”了。
解决方法
方法一:统一barTintColor与backgroundColor
将barTintColor设置为和backgroundColor相同的深色,消除色差:
UITabBar.appearance().barTintColor = UIColor(red: 0.121, green: 0.121, blue: 0.121, alpha: 1)
方法二:隐藏barTintColor层
如果不需要额外的背景层,直接将barTintColor设为透明,让backgroundColor完全显示:
UITabBar.appearance().barTintColor = .clear
额外检查(可选)
如果子ViewController的视图没有延伸到TabBar下方,可确认edgesForExtendedLayout设置(默认是自动延伸的):
// 在子ViewController的viewDidLoad中添加 edgesForExtendedLayout = .all
内容的提问来源于stack exchange,提问作者bome24
相关产品推荐
相关产品推荐

