Setting Selected Image in Tab Bar Controller with

2019-01-07 05:28发布

I am using Storyboarding and I have a tab bar controller with five tabs. In the storyboard, I am able to set the image for the tab bar item. Apple docs suggest to have two icons for each tab bar item - one for selected and one for the unselected state.

I am not able to figure out how I can do this using storyboard.

标签: ios xcode5
9条回答
一纸荒年 Trace。
2楼-- · 2019-01-07 06:15

I think that the easiest way is setting the image from the Inspector. you have a field called Bar Item -> Image, and it is in there where you have to set the image name. Watch out, not confuse with the Tab Bar Item -> Selected Image

enter image description here

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-07 06:21

In the new Xcode 8 you can do in Storyboard without needing to defined the runtime attributes as is suggested in the high pointed answer.

Print Screen Tab Bar item

Don't forget that image should have this size:

  • @1x : about 25 x 25
  • @2x : about 50 x 50
  • @3x : about 75 x 75
查看更多
时光不老,我们不散
4楼-- · 2019-01-07 06:22

Here is complete solution for selected/unselected image in Tabbar For XCode >= 8:

  • Go to Image assets -> select image
  • Select Render AS: "Original Image"

enter image description here

  • After that go to storyboard -> Select Tabbar Item
  • Under Attribute Inspectors, set "Selected Image" & "Image" as shown in following screenshot, that`s it:

enter image description here

查看更多
登录 后发表回答