Custom Font in Tabbar

后端 未结 3 499
孤城傲影
孤城傲影 2020-12-29 17:01

Hey,
is there a way to set the tabbar\'s font to e.g. Chalkboard? I\'ve seen the question for the font size and tried it with font, but the loop wouldn\'t work out.

3条回答
  •  粉色の甜心
    2020-12-29 17:50

    On iOS 13 there is a bug with UITabBarItem.appearance().setTitleTextAttributes method, so we need to do workaround like this:

        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 you only set appearance tabBar.standardAppearance = appearance on iOS 13 you'll still have a bug, but the other one

提交回复
热议问题