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

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

目录.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.
    }
    */

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,887评论 1 32
  • 如何不被束缚捆绑,如何不向现实妥协,如何不让喜欢的一切变成一座坟,如何与生之无聊无趣与死之无可避免相对抗。
    李愈阅读 1,522评论 0 0
  • 参考:深入理解Java虚拟机(第2版) 本文原文在这里,这里做记录比较方便 简单概述JVM有哪些内存区域,以及他们...
    你缺少想象力阅读 1,850评论 0 0
  • 又是一次考试,又是一次100多名,又是一次母子之间不愉快的对话。 “不能沉下心来学习”是我对儿子的...
    笨笨鸭阅读 1,396评论 0 0

友情链接更多精彩内容