1

On iOS 13 there is a bug with UITabBarItem.appearance().setTitleTextAttributes method but also there is a bug with tabBar.standardAppearance = appearance if I am using custom font in attributes

1 Answers1

1

I found the way to fix it with this workaround:

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
}

If I only set appearance tabBar.standardAppearance = appearance on iOS 13 I'll still have a bug with font.