[英]Change Tabbar background color in override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!)
I need to load tabbar items. 我需要加载标签栏项。 Here i need different background colors for tabbar in different tabs .
在这里,我需要不同选项卡中的选项卡使用不同的背景色。 i am changing bar tint color in didSelectItem.
我正在didSelectItem中更改条形颜色。 But it's background color is not changing .
但是它的背景色没有改变。 while loading tab bar it is working fine .
加载标签栏时工作正常。
Here is my code 这是我的代码
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
}
}
While loading tabbar tint color is loading fine 加载标签栏时,色调颜色加载良好
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
}
}
While changing tabbar items it's not working . 更改标签栏项目时,它不起作用。
Got Solution , making Completely transparent UITabBar in app delegate 获得解决方案,在应用程序委托中制作完全透明的UITabBar
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
And changing background color on didSelectItem 并更改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
}
}
Change UITabBar.appearance().barTintColor = Colors.TAB_BAR_ME_BG_COLOR
to tabBar.barTintColor = UIColor.yellowColor()
. 将
UITabBar.appearance().barTintColor = Colors.TAB_BAR_ME_BG_COLOR
为tabBar.barTintColor = UIColor.yellowColor()
。 Hope this help. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.