我想知道当我使用标签栏时如何更改标签中标题的字体和大小。
我查看了文档但无法找到有关标题字体和大小的任何内容 - source
答案 0 :(得分:10)
您可以通过外观代理更改它:
let font: UIFont = ...
UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: font], forState: .Normal)
Swift 4:
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: .normal)
您应该将其放在func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
答案 1 :(得分:2)
更新swift 3。
将此信息放入func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: yourFont], for: .normal)
答案 2 :(得分:0)
Swift 4.1
UITabBarItem.appearance().setTitleTextAttributes([kCTFontAttributeName as NSAttributedStringKey: font], for: .normal)