Skip to content

Instantly share code, notes, and snippets.

@feihong
Created June 26, 2015 00:25
Show Gist options
  • Save feihong/c605853821ef60a73107 to your computer and use it in GitHub Desktop.
Save feihong/c605853821ef60a73107 to your computer and use it in GitHub Desktop.
Example of using UITabBarController without using icons
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