iPadOS 15 UITabBar标题被截断

jac*_*ang 10 ios ipados

由于我升级了 iPad 操作系统,我的应用程序的 UITabBar 标题显示被截断,如屏幕截图所示。

我尝试了一些方法,但没有找到正确的解决方案。

希望可以有人帮帮我。

这是代码:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 33

由于某种原因,似乎设置 是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]
Run Code Online (Sandbox Code Playgroud)

  • 这并没有完全解决我的问题。设置默认段落样式会停止添加省略号,但文本仍然会被剪切,就好像标签框架不够大一样。这是在 iOS 15 上的 iPhone 应用程序上使用自定义字体。 (11认同)
  • 谢谢你!救了我一命!(iOS 15 上的 iPad 应用) (2认同)