Custom background on UITabBarItem not set on second tap

做~自己de王妃 提交于 2019-12-11 05:09:37

问题


I have a custom tabbar with custom tabbar items. Everything works as I want it to, besides when a tap has been tapped and is in a selected state, it does not use my custom highlighted background if re-tapped.

So far I set:

    UIButton *tap = [UIButton buttonWithType:UIButtonTypeCustom];
    [tap setBackgroundImage:img forState:UIControlStateNormal];
    [tap setBackgroundImage:[UIImage imageNamed:@"img_down"] forState:UIControlStateHighlighted];
    [tap setBackgroundImage:[UIImage imageNamed:@"img_down"] forState:UIControlStateSelected];

I've read that I may need to use the UITabBarDelegate. Any ideas?


回答1:


I needed to set:

    [tap setBackgroundImage:[UIImage imageNamed:@"img_down"] forState:(UIControlStateHighlighted|UIControlStateSelected)];;

Check this SO post for details




回答2:


[tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"star.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"star22.png"]];

change two images



来源:https://stackoverflow.com/questions/8794035/custom-background-on-uitabbaritem-not-set-on-second-tap

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