gpt4 book ai didi

swift - 在 iOS 13 上为选项卡栏设置自定义字体

转载 作者:行者123 更新时间:2023-11-30 10:32:12 28 4
gpt4 key购买 nike

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

最佳答案

我找到了使用此解决方法修复它的方法:

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 = 外观,我仍然会遇到字体错误。

关于swift - 在 iOS 13 上为选项卡栏设置自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58931787/

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