个别UITabBaritem色彩

时间:2015-12-26 11:22:00

标签: ios swift uikit uitabbarcontroller uitabbaritem

我正在尝试实施custom UITabbar

我发现的任何内容都涉及在tabbarItem上覆盖一个Re​​ctangle。 那么有没有直截了当的方法呢?

1 个答案:

答案 0 :(得分:2)

要更改单个tabBar项目色调颜色,请使用以下

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

viewWillAppear

中添加此代码

<强>更新

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

viewWillAppear中添加此代码。如果您想从应用开始加载,我建议您将其添加到AppDelegate