1

I'm trying to implement a custom UITabbar.

Anything I found involves overlaying a Rectangle over the tabbarItem. So is there any straightforward way of doing this?

Rashwan L
  • 38,237
  • 7
  • 103
  • 107

1 Answers1

2

To change an individual tabBar items tint color use the following

let tabBar = (self.tabBarController?.tabBar)! as UITabBar
tabBar.tintColor = UIColor(red: 120/255, green: 120/255, blue: 120/255, alpha: 1)

Add this code in your viewWillAppear.

Update

let tabBar = (self.tabBarController?.tabBar)! as UITabBar
// Change this index to your selected tabBar index
// 1 = second item
let index = CGFloat(1)
let itemWidth = tabBar.frame.width / CGFloat(tabBar.items!.count)
let bgView = UIView(frame: CGRectMake(itemWidth * index, 0, itemWidth, tabBar.frame.height))
bgView.backgroundColor = UIColor.redColor()
tabBar.insertSubview(bgView, atIndex: Int(index))

Add this code in your viewWillAppear. If you want to load this from the app start I would recommend to add it in your AppDelegate.

Rashwan L
  • 38,237
  • 7
  • 103
  • 107