Swift更改UITabBarItem的字体

时间:2022-06-01 12:57:08

主要是使用UItabBarItem的attribute keys来设置字体:

Swift 4

UITabBarItem.appearance()
    .setTitleTextAttributes(
        [NSAttributedStringKey.font: UIFont(name: "Didot", size: 10)!], 
    for: .normal)

Swift 3

UITabBarItem.appearance()
   .setTitleTextAttributes(
       [NSFontAttributeName: UIFont(name: "Font-Name", size: 10)!], 
   for: .normal)