【问题标题】:Set custom font to tabbar on iOS 13在 iOS 13 上将自定义字体设置为标签栏
【发布时间】:2020-03-14 20:08:42
【问题描述】:

在 iOS 13 上,UITabBarItem.appearance().setTitleTextAttributes 方法存在错误,但如果我在属性中使用自定义字体,tabBar.standardAppearance = appearance 也存在错误

【问题讨论】:

标签: swift uitabbar ios13 tabbar


【解决方案1】:

我找到了解决方法:

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12),
                  NSAttributedString.Key.paragraphStyle: paragraphStyle]

let appearance = UITabBarItem.appearance()
appearance.setTitleTextAttributes(attributes, for: .normal)

if #available(iOS 13.0, *) {
    let appearance = UITabBarAppearance()
    appearance.stackedLayoutAppearance.normal.titleTextAttributes = attributes
    appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .blue
    appearance.stackedLayoutAppearance.selected.titleTextAttributes = attributes
    appearance.stackedLayoutAppearance.selected.badgeBackgroundColor = .blue
    tabBar.standardAppearance = appearance
}

如果我只在 iOS 13 上设置外观 tabBar.standardAppearance = 外观,我仍然会遇到字体错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多