Swift-导航栏navigation

  • 设置title及title的颜色

self.navigationItem.title = "title"
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName : UIFont.systemFontOfSize(16), NSForegroundColorAttributeName : UIColor.blackColor()]
  • 设置导航栏颜色

self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
  • 设置navigation的titleView

let image = UIImage(named: "logo0")        
let imageview = UIImageView(image: image)        
let titlebtn = UIButton.init(frame: CGRectMake(DeviceWidth / 2 - 60, 32, 120, 12))        
titlebtn.addSubview(imageview)        
titlebtn.addTarget(self, action: #selector(MainViewController.refreshSelectedCluster), forControlEvents: UIControlEvents.TouchUpInside)
self.navigationItem.titleView = titlebtn
  • 设置navagation的背景颜色

self.navigationController?.navigationBar.barTintColor=UIColor.init(white:1, alpha:0.99)
  • 隐藏导航栏返回

let backWBtn = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.Stop, target: self, action: nil)        
backWBtn.tintColor = UIColor.clearColor()        
self.navigationItem.leftBarButtonItems = [left, backWBtn]
self.navigationItem.leftBarButtonItem = left
  • 导航栏-返回

let backBtn = UIBarButtonItem.init(barButtonSystemItem:UIBarButtonSystemItem.Stop, target:self, action:#selector(PhotoMainViewController.BackClick))
backBtn.tintColor = UIColor.whiteColor()
letbackBtn =UIButton(frame:CGRectMake(11.5,10,15,15))
backBtn.setImage(UIImage(named:"backbutton_x_normal"), forState:UIControlState.Normal)
backBtn.setImage(UIImage(named:"backbutton_x_highlight"), forState:UIControlState.Highlighted)
backBtn.addTarget(self, action:#selector(PhotoMainViewController.BackClick), forControlEvents: .TouchUpInside)
let left = UIBarButtonItem(customView: backBtn)

你可能感兴趣的:(Swift-导航栏navigation)