swift-導(dǎo)航欄
直接上代碼
導(dǎo)航欄整體背景顏色
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.backgroundColor = UIColor.red
導(dǎo)航欄左側(cè)按鈕 自定義
let leftItemButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 44))
leftItemButton.backgroundColor = UIColor.clear
leftItemButton.setTitle("返回" as String, for: UIControlState.normal)
leftItemButton.setTitleColor(UIColor.black, for: UIControlState.normal)
leftItemButton.titleLabel?.font = UIFont.systemFont(ofSize: CGFloat(17.0))
leftItemButton .addTarget(self, action: #selector(leftClick1), for: UIControlEvents.touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftItemButton)
導(dǎo)航欄左側(cè) 隱藏
self.navigationItem.leftBarButtonItem = nil
導(dǎo)航欄右側(cè)圖片
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage.init(named: "tarbar1_no"), style: UIBarButtonItemStyle.plain, target: self, action: #selector(leftClick2))