简体   繁体   中英

Edit background color of specific Tab bar item

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.

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 :

更改tabBarItem的背景颜色或使用背景图像并根据要求更改比赛

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM