Swift +UINavigation+UITabBar

2017-08-29  本文已影响0人  id_confidence

初次接触swift,写下demo和笔记

每一个项目的框架构成,几乎都是UINavigationController+UITabBarController,那么究竟swift如何搭建起框架。

QQ20170829-174401-HD.gif

第一步:新建几个控制器,根据项目模块决定

E084C680-09B4-41ED-8304-43EF75173402.png

第二步:纯代码实现

        let vc1:UIViewController = HomeViewController();
        let nav1 = UINavigationController(rootViewController:vc1);
        nav1.tabBarItem = UITabBarItem(title:"首页",image:UIImage(named:"icon_home_menu01"),selectedImage:UIImage(named:"icon_home_menu01_after"))
        
        let vc2:UIViewController = MarketViewController();
        let nav2 = UINavigationController(rootViewController:vc2);
        nav2.tabBarItem = UITabBarItem(title:"营销",image:UIImage(named:"icon_home_menu02"),selectedImage:UIImage(named:"icon_home_menu02_after"))
        
        let vc3:UIViewController = FundViewController();
        let nav3 = UINavigationController(rootViewController:vc3);
        nav3.tabBarItem = UITabBarItem(title:"发现",image:UIImage(named:"icon_home_menu03"),selectedImage:UIImage(named:"icon_home_menu03_after"))
        nav3.tabBarItem.badgeValue = "2";

        let vc4:UIViewController = MineViewController();
        let nav4 = UINavigationController(rootViewController:vc4);
        nav4.tabBarItem = UITabBarItem(title:"我的",image:UIImage(named:"icon_home_menu04"),selectedImage:UIImage(named:"icon_home_menu04_after"))
        nav4.tabBarItem.selectedImage = UIImage(named:"icon_home_menu02_after");

第三步:设置好导航和tabBar,然后让tabVC做跟控制器即可
 let arr = [nav1,nav2,nav3,nav4];
        let tab:UITabBarController = UITabBarController();
        tab.viewControllers = arr;
         tab.tabBar.barStyle = .blackOpaque
        tab.selectedIndex = 4; //默认选中
        self.window?.rootViewController = tab;
上一篇下一篇

猜你喜欢

热点阅读