swift 5 UITabBar的文字颜色设置
2022-01-08 本文已影响0人
Johnson_9d92
swift 5 UITabBar的文字颜色设置
第一种当时,拿到UITabBarItem的appearance 前景色
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 26)], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 26)], for: .selected)
self.tabBar.backgroundColor = UIColor.systemGray5
tabBar.barTintColor = UIColor.black
直接设置。
第二种方式在
添加每一个ChildVc,拿到
tabBarItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.gray,
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18)],
for: .normal)
tabBarItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.black,
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18)],
for: .selected)
tabBarItem?.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -15)
tabBarItem?.imageInsets = UIEdgeInsets(top: 5.5, left: 0, bottom: -5.5, right: 0)