[背景]
代码:
//create tabs let viewMessage = MessageViewController() let viewContact = ContactViewController() let viewFile = FileViewController() let viewPersonalCenter = PersonalCenterViewController() let nvcMessage = UINavigationController(rootViewController: viewMessage) nvcMessage.tabBarItem = UITabBarItem(title: mainTabs[0], image: UIImage(named:"message_unselected.png"), tag:0) let nvcContact = UINavigationController(rootViewController: viewContact) nvcContact.tabBarItem = UITabBarItem(title: mainTabs[1], image: UIImage(named:"contact_unselected.png"), tag:1) let nvcFile = UINavigationController(rootViewController: viewFile) nvcFile.tabBarItem = UITabBarItem(title: mainTabs[2], image: UIImage(named:"file_unselected.png"), tag:2) let nvcPersonalCenter = UINavigationController(rootViewController: viewPersonalCenter) nvcPersonalCenter.tabBarItem = UITabBarItem(title: mainTabs[3], image: UIImage(named:"personal_center_unselected.png"), tag:3) self.viewControllers = [nvcMessage, nvcContact, nvcFile, nvcPersonalCenter] //default select message index 0 self.selectedIndex = 0
结果使得:
UITabBarItem
中的字体小了。
想要变大点。
[解决过程]
1.搜:
UITabBarItem font size
参考:
搜:
swift setTitleTextAttributes font
参考:
let barItemFont = UIFont.systemFontOfSize(18) let nvcMessage = UINavigationController(rootViewController: viewMessage) nvcMessage.tabBarItem = UITabBarItem(title: mainTabs[0], image: UIImage(named:"message_unselected.png"), tag:0) nvcMessage.tabBarItem.setTitleTextAttributes([NSFontAttributeName: barItemFont], forState: UIControlState.Normal)
使的字体变大了:
[总结]
UITabBarItem的字体默认小,通过:
nvcMessage.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(18)], forState: UIControlState.Normal)
即可使的字体变大些了。
转载请注明:在路上 » [已解决]swift中UITabBarItem的字体太小