自从我升级了我的iPad操作系统后,我的应用程序的UITabBar标题显示为truncated,如截图所示。
我已经尝试了一些方法,但我没有找到正确的解决方案。
希望有人能帮我。
下面是代码:
func setupTabBar() {
if #available(iOS 13, *) {
let appearance = tabBar.standardAppearance
appearance.configureWithOpaqueBackground()
appearance.backgroundImage = UIImage(color: .white)
appearance.shadowImage = UIImage(color: .clear)
let normalAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.gray]
let selectedAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.red]
appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttrs
appearance.stackedLayoutAppearance.normal.titleTextAttributes = normalAttrs
appearance.inlineLayoutAppearance.selected.titleTextAttributes = selectedAttrs
appearance.inlineLayoutAppearance.normal.titleTextAttributes = normalAttrs
appearance.compactInlineLayoutAppearance.selected.titleTextAttributes = selectedAttrs
appearance.compactInlineLayoutAppearance.normal.titleTextAttributes = normalAttrs
UITabBar.appearance().standardAppearance = appearance
} else {
tabBar.backgroundImage = UIImage(color: .white)
tabBar.shadowImage = UIImage(color: .clear)
}
if #available(iOS 15, *) {
UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance
}
}

发布于 2021-10-05 21:14:02
出于某些原因,似乎设置titleTextAttributes是导致inlineLayoutAppearance出现问题的原因,而包含NSParagraphStyle.default的默认段落样式可以解决这个问题。
对于您的代码,以下更改应该可以修复它(从iOS 15.0开始)。
let normalAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.gray, .paragraphStyle: NSParagraphStyle.default]
let selectedAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.red, .paragraphStyle: NSParagraphStyle.default]https://stackoverflow.com/questions/69318520
复制相似问题