Set tab bar item selected image in xcode 6

扶醉桌前 提交于 2019-11-29 03:32:42

问题


This is my setup for a tab bar item:

However when clicking on the item inside the app the 1051-id-badge-selected image is not shown, instead nothing is shown:

Is something wrong with my setup? Any ideas?


回答1:


To get around this issue and set selected image without writing any code, we can also use "User Defined Run Attributes".

Select the tab bar item, then in 'Identity Inspector', add a new value from 'User Defined Runtime Attributes'.

Set the 'Key Path' to selectedImage, and choose 'Type' Image, then fill in the 'Value' with your image name.


If the inspector solution is not working for you (e.g. because of an Xcode bug) you can try this solution. In AppDelegate:

var tabBarController = self.window!.rootViewController as UITabBarController
let tabItems = tabBarController.tabBar.items as [UITabBarItem]

tabItems[2].selectedImage = UIImage(named: "1051-id-badge-selected.png")

Update on May 25, 2016:

On Xcode 7.3.1 the Selected Image field under Tab Bar Item section is working correctly. (But I don't know from which exact version Apple fixed it for Xcode).



来源:https://stackoverflow.com/questions/26515703/set-tab-bar-item-selected-image-in-xcode-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!