swift中UITabbarController的使用

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        
        // 视图1
        let vc01 = UIViewController()
        vc01.title = "视图1"
        vc01.view.backgroundColor = UIColor.greenColor()
        let nav01 = UINavigationController(rootViewController: vc01)
        // 视图2
        let vc02 = UIViewController()
        vc02.title = "视图2"
        vc02.view.backgroundColor = UIColor.yellowColor()
        let nav02 = UINavigationController(rootViewController: vc02)
        // 视图3
        let vc03 = UIViewController()
        vc03.title = "视图3"
        vc03.view.backgroundColor = UIColor.orangeColor()
        let nav03 = UINavigationController(rootViewController: vc03)
        // 视图4
        let vc04 = UIViewController()
        vc04.title = "视图4"
        vc04.view.backgroundColor = UIColor.brownColor()
        let nav04 = UINavigationController(rootViewController: vc04)
        // 视图5
        let vc05 = UIViewController()
        vc05.title = "视图5"
        vc05.view.backgroundColor = UIColor.blueColor()
        let nav05 = UINavigationController(rootViewController: vc05)
        // 视图6
        let vc06 = UIViewController()
        vc06.title = "视图6"
        vc06.view.backgroundColor = UIColor.redColor()
        let nav06 = UINavigationController(rootViewController: vc06)
        
        // tabbarController
        let tabbarController = UITabBarController()
        tabbarController.tabBar.barTintColor = UIColor.blackColor()
        // 注意:视图控制器超过5个时(不包含5)会自动生成一个more视图标签,用来控制第5、6、...以后的视图控制器。
        tabbarController.viewControllers = [nav01, nav02, nav03, nav04, nav05, nav06]
        // 属性设置
        // 设置默认被选中视图控制器
        tabbarController.selectedIndex = 0;
        // 设置切换视图 tabBar 属性
        // 1 打开用户交互
        tabbarController.tabBar.userInteractionEnabled = true;
        // 2 设置背景颜色
        tabbarController.tabBar.backgroundColor = UIColor.whiteColor()
        // 3 设置背景图片
        tabbarController.tabBar.backgroundImage = UIImage(named: "")
        // 4 选中时的背景图片
        tabbarController.tabBar.selectionIndicatorImage = UIImage(named: "")
        
        // 设置标题,未选中状态图标,选中状态图标
        let barItem01 = UITabBarItem(title: "第1视图", image: UIImage(named: "tabbar01_normal"), selectedImage: UIImage(named: "tabbar01_selected"))
        vc01.tabBarItem = barItem01
        let barItem02 = UITabBarItem(title: "第2视图", image: UIImage(named: "tabbar02_normal"), selectedImage: UIImage(named: "tabbar02_selected"))
        vc02.tabBarItem = barItem02
        let barItem03 = UITabBarItem(title: "第3视图", image: UIImage(named: "tabbar03_normal"), selectedImage: UIImage(named: "tabbar03_selected"))
        vc03.tabBarItem = barItem03
        let barItem04 = UITabBarItem(title: "第4视图", image: UIImage(named: "tabbar04_normal"), selectedImage: UIImage(named: "tabbar04_selected"))
        vc04.tabBarItem = barItem04
        let barItem05 = UITabBarItem(title: "第5视图", image: UIImage(named: "tabbar05_normal"), selectedImage: UIImage(named: "tabbar05_selected"))
        vc05.tabBarItem = barItem05
        let barItem06 = UITabBarItem(title: "第6视图", image: UIImage(named: "tabbar06_normal"), selectedImage: UIImage(named: "tabbar06_selected"))
        vc06.tabBarItem = barItem06
      
        // 设置字体颜色
        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: UIControlState.Normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.greenColor()], forState: UIControlState.Selected)
        // 设置字体大小
        UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(8.0)], forState: UIControlState.Normal)
        // 设置字体偏移
        UITabBarItem.appearance().titlePositionAdjustment = UIOffsetMake(0.0, -5.0)
        // 设置图标选中时颜色
        UITabBar.appearance().tintColor = UIColor.redColor()
        
        self.window!.rootViewController = tabbarController
        self.window!.makeKeyAndVisible()
        
        
        return true
    }




源码:https://github.com/potato512/SYSwiftLearning



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值