我以编程方式实现了UITabBarController。 viewControllers的标题显示更大和剪裁。这是源代码:
var tab: UITabBarController = UITabBarController()
tab.tabBar.translucent = false
var homeVC: UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as UINavigationController
homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "icon-home"), tag: 0)
var messagesNavC: UINavigationController = UIStoryboard(name: "Messages", bundle: nil).instantiateInitialViewController() as UINavigationController
messagesNavC.tabBarItem = UITabBarItem(title: "Messages", image: UIImage(named: "icon-messages"), tag: 1)
var quotesRequests: UINavigationController = UINavigationController(rootViewController: UIStoryboard(name: "QuotesRequests", bundle: nil).instantiateViewControllerWithIdentifier("RSQuoteRequestsViewController") as RSQuoteRequestsViewController) as UINavigationController
quotesRequests.tabBarItem = UITabBarItem(title: "Quotes", image: UIImage(named: "icon-quotes"), tag: 2)
var myAccount: UINavigationController = UIStoryboard(name: "MyAccount", bundle: nil).instantiateInitialViewController() as UINavigationController
myAccount.tabBarItem = UITabBarItem(title: "Account", image: UIImage(named: "icon-account"), tag: 3)
var helpVC: UINavigationController = UIStoryboard(name: "Help", bundle: nil).instantiateInitialViewController() as UINavigationController
helpVC.tabBarItem = UITabBarItem(title: "Help", image: UIImage(named: "icon-help"), tag: 4)
tab.viewControllers = [homeVC, quotesRequests, messagesNavC, myAccount, helpVC]
以下是它的外观截图。
请帮忙。提前谢谢。
答案 0 :(得分:2)
尝试更改尺寸
let appearance = UITabBarItem.appearance()
let attributes = [NSFontAttributeName:UIFont(name: "American Typewriter",size: 20)]
appearance.setTitleTextAttributes(attributes, forState: .Normal)
或者你也可以试试这个:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];