在做项目的时候,假设使用系统的UITabBarController的时候,底部的tab自己定义图片显示是蓝色和灰色的。这不是我们所想要的效果。
假设想显示自己定义的按下和弹起的图片效果。这个时候就须要对TabBarItem进行改动。
下面就是详细的演示样例:
var itemNameArray:[String] = ["down_32","add_32","plane_32","circle_32"]
var itemNameSelectArray:[String] = ["down_click_32","add_click_32","plane_click_32","circle_click_32"]
func configTabBar() {
var count:Int =
0;
let items =
self.tabBar.items
for item
in items as! [UITabBarItem] {
var image:UIImage =
UIImage(named: itemNameArray[count])!
var selectedimage:UIImage =
UIImage(named: itemNameSelectArray[count])!;
image = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
selectedimage = selectedimage.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
item.selectedImage = selectedimage;
item.image = image;
count++;
}
}