MainTabBarViewController.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // MainTabBarViewController.swift
  3. // BingHaoBang
  4. //
  5. // Created by zhangjidong on 16/3/31.
  6. // Copyright © 2016年 Zjdboy. All rights reserved.
  7. //
  8. import UIKit
  9. class MainTabBarController: UITabBarController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. addAllChildViewController()
  13. }
  14. override func didReceiveMemoryWarning() {
  15. super.didReceiveMemoryWarning()
  16. }
  17. }
  18. // MARK: - 子视图
  19. extension MainTabBarController{
  20. func addAllChildViewController(){
  21. // 首页
  22. addChildVC(IndexViewController(), title: "首页", image: "tabbar_home", selected: "tabbar_home_selected")
  23. // 发现
  24. addChildVC(FindViewController(), title: "发现", image: "tabbar_chat", selected: "tabbar_chat_selected")
  25. // 我的
  26. addChildVC(MyViewController(), title: "我的", image: "tabbar_me", selected: "tabbar_me_selected")
  27. }
  28. /**
  29. 添加子视图控制器
  30. :param: childVC NavigationViewController的根视图类型
  31. :param: title tabbar item的文字
  32. :param: image tabbar item的默认图片的名称
  33. :param: selected tabbar item的选中状态下图片的名称
  34. */
  35. func addChildVC(childVC: UIViewController, title: String?, image: String, selected: String) {
  36. childVC.tabBarItem.title = title
  37. childVC.tabBarItem.image = UIImage(named: image)
  38. childVC.tabBarItem.selectedImage = UIImage(named: selected)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
  39. // 设置点击之后字体的颜色
  40. childVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: GLOBAL_COLOR], forState:UIControlState.Selected)
  41. // 设置导航控制器
  42. let childNaviagation = UINavigationController(rootViewController: childVC)
  43. addChildViewController(childNaviagation)
  44. }
  45. }