swift创建 UITabbcontroller

//
//  DSTabBarController.swift
//  DSWeibo
//
//  Created by 刘小二 on 16/5/22.
//  Copyright © 2016年 刘小二. All rights reserved.
//

import UIKit

class DSTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 设置全局的文字图片的选中颜色
        tabBar.tintColor = UIColor.orangeColor()
        
        // 添加子控制器
        let home = HomeViewController()
        addChildViewController(childController:home, title: "首页", image: "tabbar_home", selectedImage: "tabbar_home" + "highlighted")
        let discover = DicoverViewController()
        addChildViewController(childController:discover, title: "发现", image: "tabbar_discover", selectedImage: "tabbar_discover" + "highlighted")
        let message = MessageViewController()
        addChildViewController(childController:message, title: "消息", image: "tabbar_message_center", selectedImage: "tabbar_message_center" + "highlighted")
        let mine = MineViewController()
        addChildViewController(childController: mine, title: "我的", image: "tabbar_profile", selectedImage: "tabbar_profile" + "highlighted")
    }
}


extension DSTabBarController
{
    // MARK: - 添加子控制器的方法
    func addChildViewController(childController childController: UIViewController , title: String , image : String , selectedImage : String) {
        
        childController.tabBarItem.title = title
        childController.tabBarItem.image = UIImage(named:image)
        childController.tabBarItem.selectedImage = UIImage(named: selectedImage)
        let nav = DSNavigationController(rootViewController:childController)
        addChildViewController(nav)
    }

    
}

你可能感兴趣的:(swift创建 UITabbcontroller)