2016-09-24 111 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