标题在 iOS 7 中以编程方式在 UITabBarController 中显示更大
Tittle shows bigger in UITabBarController in iOS 7 programatically
我已经以编程方式实现了 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]
这是它的外观截图。
请帮忙。提前致谢。
试试这个来改变你的尺寸
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];
我已经以编程方式实现了 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]
这是它的外观截图。
试试这个来改变你的尺寸
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];