Custom background on UITabBarItem not set on secon

2019-08-08 17:13发布

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?

2条回答
唯我独甜
2楼-- · 2019-08-08 17:39

I needed to set:

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

Check this SO post for details

查看更多
Summer. ? 凉城
3楼-- · 2019-08-08 17:41
[tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"star.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"star22.png"]];

change two images

查看更多
登录 后发表回答