gpt4 book ai didi

ios - iOS 13 中的 UITabBar 透明标签错误

转载 作者:行者123 更新时间:2023-11-28 05:37:06 25 4
gpt4 key购买 nike

iOS: 13.1.2Xcode: 11.1 (11A1027)

在我们的选项卡栏中,我们选择为选项卡项使用透明文本,因此在 iPhone 中我们只显示选项卡项图像,而文本是不可见的(它应该只在 iPad 上可见),我们通过调用:

extension UITabBarItem {
func updateTitleVisibility(for traitCollection: UITraitCollection) {
switch traitCollection.horizontalSizeClass {
case .compact:
hideTabBarTitle()
default:
showTabBarTitle()
}
}

func hideTabBarTitle() {
imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .normal)
setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .selected)
}

func showTabBarTitle() {
imageInsets = .zero
setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.licorice], for: .normal)
setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.secondaryBlue], for: .selected)
}
}

在为 iOS 13 编译我们的应用程序时(在 iOS 12 上没有发生),发生了一个奇怪的行为(注意标签栏):

Video of the bug @ Imgur

(^ 我没能把它嵌入到帖子中)

Imgur

因此,在呈现全屏 View Controller 后,非事件选项卡的选项卡文本突然显示,但当检查 View 调试器时,令人难以置信的是应该透明的标签确实透明

view debugger

有人见过这样的行为吗?我该如何修复它

最佳答案

好吧,这是由于 iOS 13 上默认深色模式下的行为所致。

要在低于 13 的 iOS 版本上使用标签实现您想要的效果,

只需将其添加到您的 Info.plist 中:

<key>UIUserInterfaceStyle</key>
<string>Light</string>

这实际上是将全局用户界面样式更改为 light 样式,这是 iOS 13 以下版本的默认样式。

如果您不想更改用户界面样式,您还可以更改选项卡栏上未选中项目的色调:

tabBar.unselectedItemTintColor = .darkGray

或您选择的任何其他色调。

关于ios - iOS 13 中的 UITabBar 透明标签错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58299076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com