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
Asked
Active
Viewed 897 times
1

Alex Shoshiashvili
- 469
- 5
- 7
-
Please check my answer on similar question https://stackoverflow.com/a/61197199/3720439 – Nikunj Acharya Apr 13 '20 at 21:37
1 Answers
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.

Alex Shoshiashvili
- 469
- 5
- 7