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

标签 swift uitabbar ios13 tabbar

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

相关文章:

swift - Apple 库 (CoreGraphics) 似乎将声明和定义分开 (Swift)

swift - Swift REPL 中的变量声明必须有初始值

iOS 7 : UITabBarItem badge z-index

ios - 如何更改 iOS 8 中选项卡栏图标的选定颜色?

swift - 如何比较两个 UIDynamicProviderColor?

list - 带有部分的 SwiftUI 动态列表未正确布局

swift - 检查数组中的素数

ios - 如何将数据从 ViewController 传递到标签栏 iOS 中的 ViewController?

ios - 如何修复 iOS 13 beta 应用程序打开应用程序时崩溃的问题?

swift - 使用超出其范围的变量