swift UITabBarController -------(项目准备-学习1)

从今天开始学习一门新的语言,可能因为有OC的基础,所以学习过程感觉不难。所以选择从项目开始直接上代码。在学习过程中再去发现问题。

swift UITabBarController -------(项目准备-学习1)_第1张图片
目录.png

UITabBarController

//
//  WMTbabarController.swift
//  BTC
//
//  Created by 智创 on 2019/3/11.
//  Copyright © 2019年 智创. All rights reserved.
//

import UIKit

class WMTbabarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        creatSubViewControllers()
    }
    
    
    
    func creatSubViewControllers(){
        
        
        let homeVc  = HomeController ()
        homeVc.tabBarItem.title = "首页"
        homeVc.tabBarItem.image = UIImage(named: "homeN")?.withRenderingMode(.alwaysOriginal)
        homeVc.tabBarItem.selectedImage = UIImage(named: "homeS")?.withRenderingMode(.alwaysOriginal)
        homeVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.lightGray], for: .normal);
        homeVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .selected)
        let homeNav = WMNavigationController(rootViewController: homeVc)
    
        
        let categoryVc = CategoryController()
        categoryVc.tabBarItem.title = "分类"
        categoryVc.tabBarItem.image = UIImage(named: "categoryN")?.withRenderingMode(.alwaysOriginal)
        categoryVc.tabBarItem.selectedImage = UIImage(named: "categoryS")?.withRenderingMode(.alwaysOriginal)
        categoryVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.lightGray], for: .normal)
        categoryVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .selected)
        let categoryNav = WMNavigationController(rootViewController: categoryVc)
        
        
        let CartVc = CartController()
        CartVc.tabBarItem.title = "购物车"
        CartVc.tabBarItem.image = UIImage(named: "cartN")?.withRenderingMode(.alwaysOriginal)
        CartVc.tabBarItem.selectedImage = UIImage(named: "cartS")?.withRenderingMode(.alwaysOriginal)
        CartVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.lightGray], for: .normal)
        CartVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .selected)
        let CartNav = WMNavigationController(rootViewController: CartVc)
        
        
        let userVc = UserController()
        userVc.tabBarItem.title = "我的"
        userVc.tabBarItem.image = UIImage(named: "userN")?.withRenderingMode(.alwaysOriginal)
        userVc.tabBarItem.selectedImage = UIImage(named: "userS")?.withRenderingMode(.alwaysOriginal)
        userVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.lightGray], for: .normal)
        userVc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .selected)
        let userNav = WMNavigationController(rootViewController: userVc)
        
        let tabArray = [homeNav, categoryNav, CartNav,userNav]
        self.viewControllers = tabArray
        
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

你可能感兴趣的:(swift UITabBarController -------(项目准备-学习1))