我正在尝试实现一个自定义UITabbar。
我发现的任何东西都需要在tabbarItem上覆盖一个矩形。那么,有什么简单的方法可以做到吗?
发布于 2015-12-26 11:25:56
若要更改单个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中。
https://stackoverflow.com/questions/34470844
复制相似问题