Changing tab bar font in Swift

后端 未结 7 1105
南方客
南方客 2020-12-16 10:03

I have been trying to change the font for the tab bar items however I haven\'t been able to find any Swift examples. I know that this is how you change it in Objective-C:

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 10:54

    In Swift4 version, you can use attribute keys to set font and foreground color

    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor(hexString: "#D8FFE8"), NSAttributedStringKey.font : UIFont(name: "HelveticaNeue-Bold", size: 16) as Any], for: .normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor(hexString: "#FFFFFF"),NSAttributedStringKey.font : UIFont(name: "HelveticaNeue-Bold", size: 16) as Any], for: .selected)
    

提交回复
热议问题