首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPadOS 15 UITabBar标题中断

iPadOS 15 UITabBar标题中断
EN

Stack Overflow用户
提问于 2021-09-24 16:41:33
回答 1查看 664关注 0票数 2

自从我升级了我的iPad操作系统后,我的应用程序的UITabBar标题显示为truncated,如截图所示。

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

希望有人能帮我。

下面是代码:

代码语言:javascript
复制
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
    }
}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-05 21:14:02

出于某些原因,似乎设置titleTextAttributes是导致inlineLayoutAppearance出现问题的原因,而包含NSParagraphStyle.default的默认段落样式可以解决这个问题。

对于您的代码,以下更改应该可以修复它(从iOS 15.0开始)。

代码语言:javascript
复制
let normalAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.gray, .paragraphStyle: NSParagraphStyle.default]
let selectedAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.red, .paragraphStyle: NSParagraphStyle.default]
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69318520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档