在 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/