Custom background on UITabBarItem not set on secon

2019-08-08 17:26发布

问题:

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