Swift UITabBarController 基本用法
来源:互联网 发布:单片机汇编指令 编辑:程序博客网 时间:2024/05/21 06:57
//// MainTabBarVC.swift// TsOneS//// Created by xubaoji on 16/3/7.// Copyright © 2016年 xubaoji. All rights reserved.//import UIKitclass MainTabBarVC: UITabBarController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. createControllers() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func createControllers() { createNavigationController(HomeViewController(), title: "首页", imageName: "icon_homepage_normal", selectedImageName: "icon_homepage_selected") createNavigationController(GoodsViewController(), title: "值得买", imageName: "icon_worthbuy_normal", selectedImageName: "icon_worthbuy_selected") createNavigationController(OtherViewController(), title: "值得去", imageName: "icon_worthgo_normal", selectedImageName: "icon_worthgo_selected") createNavigationController(ZhuantiViewController(), title: "值得看", imageName: "icon_worthlook_normal", selectedImageName: "icon_worthlook_selected") createNavigationController(UserViewController(), title: "我的", imageName: "icon_mine_normal", selectedImageName: "icon_mine_selected") let attributes = [NSForegroundColorAttributeName : APP_COLOR_PINK_1] UITabBarItem.appearance().setTitleTextAttributes(attributes, forState: .Selected) } func createNavigationController(vc:UIViewController , title: String, imageName: String, selectedImageName: String) { let selectImg = UIImage(named: selectedImageName)?.imageWithRenderingMode(.AlwaysOriginal) vc.tabBarItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage:selectImg) let nav = UINavigationController(rootViewController: vc) self.addChildViewController(nav) } /*最基本的写法 func createControllersBasic(){ let vc1 = HomeViewController() vc1.tabBarItem = UITabBarItem(title: "首页", image: UIImage(named: "icon_tabbar_homepage"), selectedImage: UIImage(named: "icon_tabbar_homepage_selected")) let nav1 = UINavigationController(rootViewController: vc1) let vc2 = HomeViewController() vc2.tabBarItem = UITabBarItem(title: "商家", image: UIImage(named: "icon_tabbar_merchant_normal"), selectedImage: UIImage(named: "icon_tabbar_merchant_selected")) let nav2 = UINavigationController(rootViewController: vc2) let vc3 = HomeViewController() vc3.tabBarItem = UITabBarItem(title: "我的", image: UIImage(named: "icon_tabbar_mine"), selectedImage: UIImage(named: "icon_tabbar_mine_selected")) let nav3 = UINavigationController(rootViewController: vc3) let vc4 = HomeViewController() vc4.tabBarItem = UITabBarItem(title: "更多", image: UIImage(named: "icon_tabbar_misc"), selectedImage: UIImage(named: "icon_tabbar_misc_selected")) let nav4 = UINavigationController(rootViewController: vc4) self.viewControllers = [nav1,nav2,nav3,nav4] } */}
swift3.0
func createControllers() { createNavigationController(vc: HomeViewController(), title: "首页", imageName: "icon_homepage_normal", selectedImageName: "icon_homepage_selected") createNavigationController(vc: GoodsViewController(), title: "值得买", imageName: "icon_worthbuy_normal", selectedImageName: "icon_worthbuy_selected") createNavigationController(vc: OtherViewController(), title: "值得去", imageName: "icon_worthgo_normal", selectedImageName: "icon_worthgo_selected") createNavigationController(vc: ZhuantiViewController(), title: "值得看", imageName: "icon_worthlook_normal", selectedImageName: "icon_worthlook_selected") createNavigationController(vc: UserViewController(), title: "我的", imageName: "icon_mine_normal", selectedImageName: "icon_mine_selected") let attributes = [NSForegroundColorAttributeName : UIColor.black] UITabBarItem.appearance().setTitleTextAttributes(attributes, for: UIControlState.selected) } func createNavigationController(vc:UIViewController , title: String, imageName: String, selectedImageName: String) { let selectImg = UIImage(named: selectedImageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal) vc.tabBarItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage:selectImg) let nav = UINavigationController(rootViewController: vc) self.addChildViewController(nav) }
0 0
- Swift UITabBarController 基本用法
- ios--UITabBarController基本用法1
- Swift 开发:UINavigationController和UITabBarController用法案例
- ios--UITabBarController的基本用法3
- swift基本用法
- UITabBarController用法
- UITabBarController用法
- UITabBarController用法
- Swift 中UITabBarController使用方法
- Swift之UITabBarController
- ios swift UITabBarController
- Swift ☞ 自定义UITabBarController
- Swift 设置UITabBarController
- iOS - Swift 自定义UITabBarController
- iOS Swift创建UITabBarController
- Swift 字典 Dictionary基本用法
- UITabBarController的基本使用方法
- UITabbarController基本应用
- 102 - Binary Tree Level Order Traversal(DFS)
- 判断手机端登录的js代码
- 二分查找中的精度问题
- ajaxSubmit和ajaxForm提交form表单
- Hadoop中的YARN
- Swift UITabBarController 基本用法
- c#字符串 取最后一个符号前的字符
- 反素数
- SAP接口编程-RFC系列14 : 获取SAP DDIC的数据字段
- Oracle动态查拆分号票,合并号段
- git - 简明指南
- C语言解析http请求表单内容
- 机器学习系列(3)_逻辑回归应用之Kaggle泰坦尼克之灾
- poj 2965 The Pilots Brothers' refrigerator 飞行员兄弟的冰箱?