最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中实现tab点击选中和没有选中时分别设置不同的图片

Swift crifan 2475浏览 0评论

existing selected and nonselected image 希望放到tab中:

put to selected tab image
实现:
没有选中,是白色那组图片
选中了,是蓝色的那组图片
[解决过程]

1.搜:

swift tab selected unselected image
参考:

ios – How to change inactive icon/text color on tab bar? – Stack Overflow

然后用:
       nvcConversation.tabBarItem = UITabBarItem(title: mainTabs[0], image: UIImage(named:"tab_conversation"), tag:0)
        nvcConversation.tabBarItem.selectedImage = UIImage(named: "tab_conversation_selected")
即可:
未选中tab时候和选中tab的时候,分别显示对应的图片。
又按照类似的写法,添加余下tab的selected图片,效果是:
all tab selected image  show ok
[总结]
设置tab是否选中而显示不同的图片,可以写成:
       vc.tabBarItem = UITabBarItem(title: "xxx", image: UIImage(named:"tab_conversation"), tag:0)
        vc.tabBarItem.selectedImage = UIImage(named: "tab_conversation_selected")
即可。

转载请注明:在路上 » [已解决]swift中实现tab点击选中和没有选中时分别设置不同的图片

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.169 seconds, using 22.08MB memory