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)
    }

    
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容