Swift 去除默认颜色

swift 去除 tabbarItem 的ImageView及文字的默认颜色

let items =self.tabBar.items

for item in items{

      item.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.self_darkgreyColour()],

forState:UIControlState.Selected)

item.selectedImage= selectImgs[i]

item.image= imgs[i]

}

1.先获取tabBar的所有item ,然后遍历所有item,使用setTitleTextAttributes()方法设置文字颜色,UIControlState.Selected为选中时的颜色 ,也可以使用NSFontAttributeName:UIFont.systemFontOfSize(12.0)设置字体大小

2.去除图片的默认颜色:

let leftImage=UIImage(named:"homepage_icon")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

let leftButton =UIBarButtonItem(image: leftImage, style:UIBarButtonItemStyle.Done, target:self, action:"closeController")

self.navigationItem.leftBarButtonItem= letButton

你可能感兴趣的:(Swift 去除默认颜色)