0

Hey i would like to change the background Color of my center tab bar item like instagram in swift, anyone who knows how it works. I googled but can't find any helpful answer.

telip007
  • 27
  • 7
  • 1
    Set a background image of Tabbar control 'setBackgroundImage' with center color changed, make sure about sizes for color ur center/perticuler tab background. – Viral Savaj Sep 02 '15 at 10:59

2 Answers2

1

You can use the following code :

// 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)

For reference you can look into these Stackoverflow posts :

Community
  • 1
  • 1
Munahil
  • 2,381
  • 1
  • 14
  • 24
-2

Change Background color of tabBarItem or use Background Image and change contest according to requirement

baydi
  • 1,003
  • 6
  • 11
  • How does this even attempt to answer the question. This is clearly a comment and not an answer. – Popeye Sep 02 '15 at 11:14
  • The Problem is I don't know how to change the background color, there is no type background color for tab bar item – telip007 Sep 02 '15 at 11:26
  • Use this link to perform your process in swift http://stackoverflow.com/questions/30041127/ios-8-tab-bar-item-background-colour – baydi Sep 02 '15 at 11:37