Swift之UITabBarController 导航控制器颜色的改变

废话不多 直接上代码

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

self.window!.backgroundColor = UIColor.whiteColor()

let firstVC = OneViewController();//第一个标签对应的控制器

let nav1=UINavigationController(rootViewController:firstVC);

let image1=UIImage(named:"shenfen_icon");//标签对应的图片

nav1.tabBarItem=UITabBarItem(title:"完美食材",image:image1,tag:1);

let secondVC = TwoViewController();//第二个标签对应的控制器

let nav2=UINavigationController(rootViewController:secondVC);

let image2=UIImage(named:"shenfen_icon");

nav2.tabBarItem=UITabBarItem(title:"国色天香",image:image2,tag:2);

  nav2.tabBarItem.badgeValue = "2"        //设置该控制器对应的标签图片右上角显示的值

let thirdVC = ThreeViewController();//第三个标签对应的控制器

let nav3=UINavigationController(rootViewController:thirdVC);

let image3=UIImage(named:"tanhao");

nav3.tabBarItem=UITabBarItem(title:"实惠经典",image:image3,tag:3);

let navArr=[nav1,nav2,nav3];

let tabBarController = RootTabBarController()

tabBarController.viewControllers=navArr; //把控制器交给tabbar

tabBarController.tabBar.tintColor = UIColor.orangeColor() //tabbar标签和图片的颜色都会更改

  //改变文字颜色
  UITabBarItem.appearance().setTitleTextAttributes(
      [NSForegroundColorAttributeName: UIColor.grayColor()], forState:.Normal)
  UITabBarItem.appearance().setTitleTextAttributes(
      [NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)

  tabBarController.tabBarItem =  UITabBarItem(title: "QQ", image: UIImage(named: "qq_color"),

selectedImage: UIImage(named: "qq_color")?.imageWithRenderingMode(.AlwaysOriginal))//原始的图片

tabBarController.selectedIndex = 1//默认选中第几个控制器

self.window!.rootViewController=tabBarController;//把tababr设置为根视图

        self.window!.makeKeyAndVisible()

return true

上一篇:Scrambled Polygon - POJ 2007(求凸包)


下一篇:如何解决谷歌Chrome浏览器空白页的问题