swift-导航栏
直接上代码
导航栏整体背景颜色
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.backgroundColor = UIColor.red
导航栏左侧按钮 自定义
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)
导航栏左侧 隐藏
self.navigationItem.leftBarButtonItem = nil
导航栏右侧图片
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage.init(named: "tarbar1_no"), style: UIBarButtonItemStyle.plain, target: self, action: #selector(leftClick2))
参考:swift导航栏的设置