關(guān)于創(chuàng)建tabBar和視圖控制器的部分就不啰嗦了究反,我們來(lái)研究一下樣式的修改( ⊙o⊙ )
一玄柏、修改圖片和文字的顏色
(1)圖片和文字同時(shí)修改
self.tabBar.tintColor = UIColor.orangeColor()
(2)只改變文字的顏色
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.grayColor()], forState:.Normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
(3)只改變圖片的顏色
self.tabBar.tintColor = UIColor.orangeColor()
//文字顏色還原
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: self.view.tintColor], forState:.Selected)
二、選中時(shí)戏自、不選中時(shí)使用不同的圖片
在默認(rèn)的item選中壁酬、不選中使用的是同一張照片,只是顏色不同辖所。其實(shí)我們也可以使用兩張不同圖片表示兩種狀態(tài)惰说。
apple.tabBarItem = UITabBarItem(title: "apple", image: UIImage(named: "apple"),selectedImage: UIImage(named: "apple_active"))
android.tabBarItem = UITabBarItem(title: "Android", image: UIImage(named: "android"),selectedImage: UIImage(named: "android_active"))
三、使用圖片的原始顏色
默認(rèn)情況下缘回,不管原圖是什么顏色吆视,渲染器都會(huì)講渲染成單一顏色典挑。
apple.tabBarItem = UITabBarItem(title: "apple", image: UIImage(named: "apple_color"),selectedImage: UIImage(named:"apple_color")?.imageWithRenderingMode(.AlwaysOriginal))
android.tabBarItem = UITabBarItem(title: "Android", image: UIImage(named: "android_color"),selectedImage: UIImage(named: "android_color")?.imageWithRenderingMode(.AlwaysOriginal))