zoukankan      html  css  js  c++  java
  • 32.怎样在Swift中实现TabBar和导航视图结合的项目?

      导航栏和TabBar结合的项目,在我们平常开发中会经常看到,下面我们通过自定义的TabBar来实现一个导航和TabBar结合的Demo。

    1.自定义TabBar

    import UIKit
    
    class GofTabBarController: UITabBarController
    {
        override func viewDidLoad()
        {
            super.viewDidLoad();
            
            addTabBarChildViewController(GofMainViewController(), title: "首页", imageName: "tab_home", selectedImageName: "tab_home_sel", tag: 0);
            addTabBarChildViewController(GofDrugViewController(), title: "药品列表", imageName: "tab_drug", selectedImageName: "tab_drug_sel", tag: 1);
            addTabBarChildViewController(GofShopcartViewController(), title: "购物车", imageName: "tab_shopcart", selectedImageName: "tab_shopcart_sel", tag: 2);
            addTabBarChildViewController(GofMyViewController(), title: "我的", imageName: "tab_my", selectedImageName: "tab_my_sel", tag: 3);
        }
        
        private func addTabBarChildViewController(childVC: UIViewController, title: String, imageName: String, selectedImageName: String, tag: Int)
        {
            let vcItem = UITabBarItem(title: title, image: gof_ImageWithName(imageName), selectedImage: gof_ImageWithName(selectedImageName)?.imageWithRenderingMode(.AlwaysOriginal));
            vcItem.tag = tag;
            childVC.tabBarItem = vcItem;
            
            let navigationVC = UINavigationController(rootViewController: childVC);
            addChildViewController(navigationVC);
        }
        
        override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem)
        {
            printLog("didSelectIndex:(item.tag)");
        }
    }

    2.怎么使用?

    let vc = GofTabBarController();
    self.window?.rootViewController = vc;
  • 相关阅读:
    xpath元素定位 绝对路径改成相对路径
    jmeter(十一)csv读取中文乱码问题
    jmeter(十)上传文件遇到的奇葩问题
    jmeter(八)Synchronizing Timer的使用
    jmeter.properties配置文件修改
    jmter命令行-生成压力测试报告
    python(二)字符串、列表、数组、元组、字典
    python配置虚拟环境和包
    验证码测试
    性能测试面试题
  • 原文地址:https://www.cnblogs.com/LeeGof/p/5685595.html
Copyright © 2011-2022 走看看