I want to change the background color of a middle TabBarItem. In this image home is selected and middle tab is not selected.
Asked
Active
Viewed 52 times
2 Answers
0
Check this...
// Add background color to middle tabBarItem
let itemIndex = 2
let bgColor = UIColor(red: 0.08, green: 0.726, blue: 0.702, alpha: 1.0)
let itemWidth = tabBar.frame.width / CGFloat(tabBar.items!.count)
let bgView = UIView(frame: CGRectMake(itemWidth * itemIndex, 0, itemWidth, tabBar.frame.height))
bgView.backgroundColor = bgColor
tabBar.insertSubview(bgView, atIndex: 0)

DJ1
- 936
- 15
- 29
0
You can try like,
NSArray *arr = self.tabBarController.tabBar.subviews;
NSLog(@"tabbar subview : %@",arr);
UIButton *button = (UIButton*)[arr objectAtIndex:3];
button.backgroundColor = [UIColor greenColor];
In your first viewcontroller of your tabbarcontroller.

Ketan Parmar
- 27,092
- 9
- 50
- 75