swift UITabBarController -------(項目準備-學(xué)習(xí)1)

從今天開始學(xué)習(xí)一門新的語言,可能因為有OC的基礎(chǔ),所以學(xué)習(xí)過程感覺不難。所以選擇從項目開始直接上代碼。在學(xué)習(xí)過程中再去發(fā)現(xiàn)問題。

目錄.png

UITabBarController

//
//  WMTbabarController.swift
//  BTC
//
//  Created by 智創(chuàng) on 2019/3/11.
//  Copyright ? 2019年 智創(chuàng). 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.
    }
    */

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,644評論 1 32
  • 如何不被束縛捆綁,如何不向現(xiàn)實妥協(xié),如何不讓喜歡的一切變成一座墳,如何與生之無聊無趣與死之無可避免相對抗。
    李愈閱讀 221評論 0 0
  • 參考:深入理解Java虛擬機(第2版) 本文原文在這里,這里做記錄比較方便 簡單概述JVM有哪些內(nèi)存區(qū)域,以及他們...
    你缺少想象力閱讀 306評論 0 0
  • 又是一次考試,又是一次100多名,又是一次母子之間不愉快的對話。 “不能沉下心來學(xué)習(xí)”是我對兒子的...
    笨笨鴨閱讀 215評論 0 0

友情鏈接更多精彩內(nèi)容