美文网首页
标签栏视图控制器

标签栏视图控制器

作者: theDeskmateOfSb | 来源:发表于2016-09-05 18:48 被阅读0次

    标签栏视图控制器

    1.首先创建一个类继承UITabBarController
    2.然后创建一个标签栏控制器的对象
    3.把对象添加给Window的跟视图上

            self.window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
            self.window?.backgroundColor = UIColor.whiteColor()
    
            //2.创建标签栏控制器
            //a.创建对象
            let tabBarC = YTTabBarController()
            //b.将需要交给标签栏控制器管理的视图控制器对象创建出来
            //c.将视图控制器交给标签栏控制器管理
            //标签控制器会自动创建每个视图控制器对应标签
            //注意:标签栏控制器的标签栏上最多能显示5个标签。如果有超过5个子视图控制器,那么第5个和超出的视图控制器的标签会被"more"标签代替
            tabBarC.viewControllers = [one,two,there,four,five,six]
            //d.设置默认选中的标签
            tabBarC.selectedIndex = 2
            //3.将标签栏控制器作为window的根视图控制器
            self.window?.rootViewController = tabBarC
    ===============定制标签控制器的视图=======
                //设置tabBarItem
                //a.设置文字
                one.tabBarItem.title = "条漫"
                //b.设置图片
                //正常状态下的图片
                one.tabBarItem.image = UIImage.init(named: "tiaoman_u")?.imageWithRenderingMode(.AlwaysOriginal)
                //选中状态的图片
                one.tabBarItem.selectedImage = UIImage.init(named: "tiaoman_d")?.imageWithRenderingMode(.AlwaysOriginal) 
                
                //1.拿到所有的tabBarItem对象
            let items = self.tabBar.items
                //c.设置文字选中颜色
            self.tabBar.tintColor = UIColor.orangeColor()
     =================设置本地数据=========
             NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isOpenBefore")
    
    

    相关文章

      网友评论

          本文标题:标签栏视图控制器

          本文链接:https://www.haomeiwen.com/subject/psgrettx.html