從今天開始學(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.
}
*/
}