我需要加载选项卡项目。在这里,我需要不同的背景色在不同的标签栏。我在didSelectItem中改变条形色调。但它的背景色并没有改变。当加载选项卡栏时,它工作正常。
这是我的密码
override func viewDidLoad() {
if(tabIndex == 1){
UITabBar.appearance().tintColor = UIColor.whiteColor()
UITabBar.appearance().barTintColor = Colors.TAB_BAR_ALBUM_BG_COLOR
self.view.backgroundColor = Colors.TAB_BAR_ALBUM_BG_COLOR
}else if(tabIndex == 2){
UITabBar.appearance().tintColor = UIColor.whiteColor()
UITabBar.appearance().barTintColor = Colors.TAB_BAR_ME_BG_COLOR
self.view.backgroundColor = Colors.TAB_BAR_ME_BG_COLOR
}
}加载选项卡颜色时,颜色很好。
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
UITabBar.appearance().tintColor = UIColor.whiteColor()
if(item.tag == 1){
UITabBar.appearance().barTintColor = Colors.TAB_BAR_ALBUM_BG_COLOR
self.view.backgroundColor = Colors.TAB_BAR_ALBUM_BG_COLOR
}else if(item.tag == 2){
UITabBar.appearance().barTintColor = Colors.TAB_BAR_ME_BG_COLOR
self.view.backgroundColor = Colors.TAB_BAR_ME_BG_COLOR
}
}当更改选项卡项时,它不起作用。
发布于 2015-10-26 09:17:54
获得解决方案,在app委托中制作完全透明的UITabBar
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];以及在didSelectItem上改变背景色
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
println(" selected index \(item.tag)")
if(item.tag == 0){
dismissViewControllerAnimated(true, completion: nil)
}
if(item.tag == 1){
self.view.backgroundColor = Colors.TAB_BAR_ALBUM_BG_COLOR
}else if(item.tag == 2){
self.view.backgroundColor = Colors.TAB_BAR_ME_BG_COLOR
}
}发布于 2015-10-26 09:13:55
将UITabBar.appearance().barTintColor = Colors.TAB_BAR_ME_BG_COLOR更改为tabBar.barTintColor = UIColor.yellowColor()。希望能帮上忙。
https://stackoverflow.com/questions/33340355
复制相似问题