在swift中取消选择时,setTitleTextAttributes对UITabBarItem不起作用 [英] setTitleTextAttributes doesn't work for UITabBarItem when it is unselected in swift
本文介绍了在swift中取消选择时,setTitleTextAttributes对UITabBarItem不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试自定义 UITabBarController
。我把它嵌入在我的 UIViewController
中,我还为这个 UITabBarController
创建了一个类。
I am trying to custom my UITabBarController
. I have it embedded in my UIViewController
, I also created a class for this UITabBarController
.
override func viewDidLoad() {
super.viewDidLoad()
//custom tab bar
self.tabBar.barTintColor = UIColor(red: 0.0/255.0, green: 102.0/255.0, blue: 153.0/255.0, alpha: 1)
self.tabBar.tintColor = UIColor(red: 171.0/255.0, green: 203.0/255.0, blue: 61.0/255.0, alpha: 1)
self.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:UIControlState.Normal)
self.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:UIControlState.Disabled)
for item in self.tabBar.items as [UITabBarItem]
{
item.image = item.selectedImage.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
}
// Do any additional setup after loading the view.
}
setTitleTextAttributes
doesn' t对标签栏项目有任何影响。有人可以帮我找出错误的位置吗?
setTitleTextAttributes
doesn't have any effects on the tab bar item. Can somebody please help me to find where the error is?
推荐答案
以下是适用于本案例的代码UITabBarController:
Here is the code that works in this case to put still in the UITabBarController:
override func viewDidLoad() {
super.viewDidLoad()
//custom tab bar
self.tabBar.barTintColor = UIColor(red: 0.0/255.0, green: 102.0/255.0, blue: 153.0/255.0, alpha: 1)
self.tabBar.tintColor = UIColor(red: 171.0/255.0, green: 203.0/255.0, blue: 61.0/255.0, alpha: 1)
for item in self.tabBar.items as [UITabBarItem]
{
item.image = item.selectedImage.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:UIControlState.Normal)
item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:UIControlState.Disabled)
item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 171.0/255.0, green: 203.0/255.0, blue: 61.0/255.0, alpha: 1)], forState:UIControlState.Selected)
}
}
这篇关于在swift中取消选择时,setTitleTextAttributes对UITabBarItem不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文