当 UITabbar 是半透明的并且 UIViewController 没有扩展到 tabbar 后面时,uitabbar 看起来像是覆盖了一个黑色视图
When the UITabbar is Translucent and the UIViewController is not extended behind the tabbar, the uitabbar seems like covering a black view
第一个视图中的标签栏是我想要的。因为第二个视图不是滚动视图,所以我无法使用 self.edgesForExtendedLayout = UIRectEdge.Bottom
.
将其扩展到底部
看起来无法接受。
而且我不想将 uitabbar 的 Translucent
设置为 false
,这并不花哨。
我换个方式试试:
[[UITabBar appearance] setBarTintColor: [UIColor whiteColor]];
没用。为了让它看起来更清晰,我将颜色更改为红色。最后一个标签栏看起来也覆盖了一些黑色视图。
Consider of the tabbar is translucent, what's the view under the UITabbar view?
这是为什么在更改条形图的 tintcolor 时不起作用的最终答案。因为UITabbar视图下的view是黑色的。
感谢 Xcode 很棒的调试功能。我们可以很容易地定位到UITabbar视图下的视图。
它是 UIWindow。所以解决办法就是简单地将window的backgroundColor
改成白色。
我想说在您的 viewController 的 viewDidLoad
中添加此代码将解决您的问题:
edgesForExtendedLayout = .all
extendedLayoutIncludesOpaqueBars = true
此外,您可以保持 tabBar
半透明且不设置任何背景颜色。
第一个视图中的标签栏是我想要的。因为第二个视图不是滚动视图,所以我无法使用 self.edgesForExtendedLayout = UIRectEdge.Bottom
.
看起来无法接受。
而且我不想将 uitabbar 的 Translucent
设置为 false
,这并不花哨。
我换个方式试试:
[[UITabBar appearance] setBarTintColor: [UIColor whiteColor]];
没用。为了让它看起来更清晰,我将颜色更改为红色。最后一个标签栏看起来也覆盖了一些黑色视图。
Consider of the tabbar is translucent, what's the view under the UITabbar view?
这是为什么在更改条形图的 tintcolor 时不起作用的最终答案。因为UITabbar视图下的view是黑色的。
感谢 Xcode 很棒的调试功能。我们可以很容易地定位到UITabbar视图下的视图。
它是 UIWindow。所以解决办法就是简单地将window的backgroundColor
改成白色。
我想说在您的 viewController 的 viewDidLoad
中添加此代码将解决您的问题:
edgesForExtendedLayout = .all
extendedLayoutIncludesOpaqueBars = true
此外,您可以保持 tabBar
半透明且不设置任何背景颜色。