2016-09-24 114 views
0

我想要将标签栏项目图像的默认颜色更改为图像的原始颜色(黑色),而不是选择灰色时的颜色。IOS - 标签栏项目图像修改

我也想要将标签栏项目图像更改为填充版本,一旦它被选中。

最后一件事是位置..它似乎期望在它下面的文本,所以它不居中,我如何居中垂直,可能使它更小?

我这种方式目前设置它:

let profileNavController = UINavigationController(rootViewController: profileController) 
     profileNavController.tabBarItem.image = UIImage(named: "icon_tab_user") 

这是它看起来如何选定和未选定: enter image description here enter image description here

回答

0

我能够更改高亮显示和未高亮显示的图像,以及与此位置:

let profileNavController = UINavigationController(rootViewController: profileController) 
     let profileTabBarItem = UITabBarItem(title: nil, image: UIImage(named: "icon_tab_user")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), selectedImage: UIImage(named: "icon_tab_user_highlighted")) 
     profileTabBarItem.imageInsets = UIEdgeInsetsMake(5.5, 0, -5.5, 0) 
     profileNavController.tabBarItem = profileTabBarItem 
0

从我们知道苹果,

默认情况下,实际未选中和选定的图像将根据源图像中的alpha值自动创建。为了防止系统着色,请提供带有UIImageRenderingModeAlwaysOriginal的图像。

看看这里。
Changing tab bar item image and text color iOS