【发布时间】:2015-05-21 08:26:41
【问题描述】:
当我创建导航栏时,我可以在左侧项目、右侧项目和标题视图中放置三个按钮,但只有左右项目有动画,并且我不能更改标题按钮的颜色。
导航栏中按钮的创建:
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "VOYAGE", style: UIBarButtonItemStyle.Plain, target: self, action: "goToPage1:")
var buttonCenter = UIButton()
buttonCenter.setTitle("PHOTOS", forState: .Normal)
buttonCenter.setTitleColor(UIColor.whiteColor(), forState: .Normal)
buttonCenter.addTarget(self, action: "goToPage2:", forControlEvents: .TouchUpInside)
self.navigationItem.titleView = buttonCenter
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "SIGHTINGS", style: UIBarButtonItemStyle.Plain, target: self, action: "goToPage3:")
触摸按钮时颜色的变化:
函数 goToPage1 :
self.navigationItem.leftBarButtonItem!.tintColor = UIColor(red: 174/255, green: 211/255, blue: 43/255, alpha: 1)
self.navigationItem.titleView!.tintColor = UIColor.whiteColor()
self.navigationItem.rightBarButtonItem!.tintColor = UIColor.whiteColor()
函数 goToPage2 :
self.navigationItem.leftBarButtonItem!.tintColor = UIColor.whiteColor()
self.navigationItem.titleView!.tintColor = UIColor(red: 174/255, green: 211/255, blue: 43/255, alpha: 1)
self.navigationItem.rightBarButtonItem!.tintColor = UIColor.whiteColor()
函数 goToPage3 :
self.navigationItem.leftBarButtonItem!.tintColor = UIColor.whiteColor()
self.navigationItem.titleView!.tintColor = UIColor.whiteColor()
self.navigationItem.rightBarButtonItem!.tintColor = UIColor(red: 174/255, green: 211/255, blue: 43/255, alpha: 1)
你对按钮的选择动画有什么想法吗?
感谢您的帮助。
【问题讨论】:
-
我可能错了,但我认为您需要更改按钮中心的颜色而不是 titleView 了
-
我试过但没用
-
你用了吗 buttonCenter.backgroundColor = UIColor.whiteColor()
-
我已经创建了“var buttonCenter: UIButton?”我启动了 viewDidLoad 中的按钮,但颜色没有改变。
-
也许您可以尝试设置按钮颜色并将其重新分配给 navigationItem.titleView 每次您希望更改颜色时。例如:buttonCenter.setTitleColor(UIColor.whiteColor(), forState: .Normal) self.navigationItem.titleView = buttonCenter
标签: swift ios8 uibutton navigationbar