Created
June 26, 2015 00:25
-
-
Save feihong/c605853821ef60a73107 to your computer and use it in GitHub Desktop.
Example of using UITabBarController without using icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import FontAwesome | |
| class MainViewController: UITabBarController { | |
| override func viewWillAppear(animated: Bool) { | |
| addViewControllers( | |
| ("Phrases", PhrasesViewController()), | |
| ("Voices", VoicesViewController()), | |
| ("Options", OptionsViewController()) | |
| ) | |
| tabBar.translucent = false | |
| // Make font larger. | |
| let font = UIFont.systemFontOfSize(17) | |
| UITabBarItem.appearance().setTitleTextAttributes( | |
| [NSFontAttributeName: font], forState: .Normal) | |
| // Move text up to center it within the tab bar. | |
| UITabBarItem.appearance().setTitlePositionAdjustment(UIOffsetMake(0, -14)) | |
| } | |
| typealias ViewControllerConfig = (String, UIViewController) | |
| func addViewControllers(configs: ViewControllerConfig...) { | |
| var list: [AnyObject] = [] | |
| for (title, vc) in configs { | |
| let nc = UINavigationController(rootViewController: vc) | |
| vc.title = title | |
| list.append(nc) | |
| } | |
| self.viewControllers = list | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment