更改 UIButton 标题导航栏的颜色
Change color of the UIButton title navigation bar
当我创建我的导航栏时,我可以在左项、右项和标题视图中放置三个按钮,但只有左项和右项有动画,我无法更改标题的颜色按钮。
导航栏按钮的创建:
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)
你对按钮的选择动画有想法吗?
感谢您的帮助。
您可以尝试以下步骤:
在main.storyboard中,对于每个视图,您可以在模拟指标部分将顶部栏的值更改为半透明导航栏
在创建按钮的导航项中添加
link 将 main.storyboard 中的按钮添加到您的文件中,并使用 self.yourButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
更改颜色
当我创建我的导航栏时,我可以在左项、右项和标题视图中放置三个按钮,但只有左项和右项有动画,我无法更改标题的颜色按钮。
导航栏按钮的创建:
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)
你对按钮的选择动画有想法吗?
感谢您的帮助。
您可以尝试以下步骤:
在main.storyboard中,对于每个视图,您可以在模拟指标部分将顶部栏的值更改为半透明导航栏
在创建按钮的导航项中添加
link 将 main.storyboard 中的按钮添加到您的文件中,并使用
self.yourButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
更改颜色