//此方法颜色显示不正确
func setUpRightNav() {
let topNav = UIBarButtonItem.init(title: "TOP", style:.Plain, target: self, action: #selector(topBtnClick))
topNav.setTitleTextAttributes([NSFontAttributeName:UIFont(name: "Verdana-BoldItalic", size: 16)!,
NSForegroundColorAttributeName:UIColor.lightGrayColor()], forState: .Normal)
topNav.setTitleTextAttributes([NSFontAttributeName:UIFont(name: "Verdana-BoldItalic", size: 16)!,
NSForegroundColorAttributeName:UIColor.blackColor()], forState: .Selected)
let newNav = UIBarButtonItem.init(title: "NEW", style:.Plain, target: self, action: #selector(newBtnClick))
newNav.setTitleTextAttributes( [NSFontAttributeName:UIFont(name: "Verdana-BoldItalic", size: 16)!,
NSForegroundColorAttributeName:UIColor.lightGrayColor()], forState: .Normal)
newNav.setTitleTextAttributes([NSFontAttributeName:UIFont(name: "Verdana-BoldItalic", size: 16)!,
NSForegroundColorAttributeName:UIColor.blackColor()], forState: .Selected)
let lineView = UIView(frame: CGRectMake(0, 0, 1, 25))
lineView.backgroundColor = UIColor.lightGrayColor()
let middleNav = UIBarButtonItem.init(customView: lineView)
self.navigationItem.rightBarButtonItems = [newNav,middleNav,topNav]
}
//解决方法
func setUpRightNav() {
let newBtn = UIButton(type: .Custom)
newBtn.setTitleColor(UIColor.lightGrayColor(), forState: .Normal)
newBtn.setTitleColor(UIColor.redColor(), forState: .Highlighted)
newBtn.setTitle("NEW", forState: .Normal)
newBtn.titleLabel?.font = UIFont(name: "Verdana-BoldItalic", size: 16)
newBtn.frame = CGRectMake(0, 20, 44, 30)
newBtn.addTarget(self, action: #selector(newBtnClick), forControlEvents: .TouchUpInside)
let newNav = UIBarButtonItem.init(customView: newBtn)
let topBtn = UIButton(type: .Custom)
topBtn.setTitleColor(UIColor.lightGrayColor(), forState: .Normal)
topBtn.setTitleColor(UIColor.redColor(), forState: .Highlighted)
topBtn.setTitle("TOP", forState: .Normal)
topBtn.titleLabel?.font = UIFont(name: "Verdana-BoldItalic", size: 16)
topBtn.frame = CGRectMake(0, 20, 44, 30)
topBtn.addTarget(self, action: #selector(topBtnClick), forControlEvents: .TouchUpInside)
let topNav = UIBarButtonItem.init(customView: topBtn)
let lineView = UIView(frame: CGRectMake(0, 0, 1, 25))
lineView.backgroundColor = UIColor.lightGrayColor()
let middleNav = UIBarButtonItem.init(customView: lineView)
self.navigationItem.rightBarButtonItems = [newNav,middleNav,topNav]
}