0

I want to change the background color of a middle TabBarItem. In this image home is selected and middle tab is not selected.

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ajay
  • 1
  • 1

2 Answers2

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