在使用UITabBarController的时候,项目中几乎都会使用自定义的TabBarItem图片以及文字的颜色,很少使用苹果自带的。如果你只是使用苹果自带的图片以及默认文字颜色,请跳过这篇文章。😊
1.更改TabBarItem的文字颜色
UITabBar.appearance().tintColor = UIColor.greenColor()
2.更改TabBarItem的选中与未选中的图片
let images = [ "ic_home_normarl", "ic_profile_normarl" ]
let pressedImages = [ "ic_home_pressed", "ic_profile_pressed" ]
let items = self.tabBar.items! as [UITabBarItem]
var count = 0
for tabBarItem in items {
var image = UIImage(named: images[count])
var selectedimage = UIImage(named: pressedImages[count])
image = image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
selectedimage = selectedimage!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
tabBarItem.image = image
tabBarItem.selectedImage = selectedimage
count = count + 1
}
注:image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
这句话要加不然没有效果;
如需转载,转载请标注转载地址,谢谢。
网友评论