在做项目的时候,如果使用系统的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++;
}
}
原文链接:https://www.f2er.com/swift/326561.html