swift导航栏的初始化设置

UIApplication.shared.statusBarStyle = .lightContent

UINavigationBar.appearance().barTintColor = VCRGBColor(r: 18, g: 19, b: 20, a: 1);

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white,NSFontAttributeName: UIFont .boldSystemFont(ofSize: 17)]

导航栏返回按钮的设置 放到每个跟控制器 去操作 

override func viewDidLoad() {

super.viewDidLoad()

self.view.backgroundColor = VCBaseViewColor()

let button = UIButton.init(type: .custom)

button.frame = VCCGRect(x: 0, y: 0, width: 40, height: 40)

button.setImage(UIImage.init(named: "YXCommonBack"), for: .normal)

button.contentHorizontalAlignment = UIControlContentHorizontalAlignment(rawValue: 1)!

button.addTarget(self, action: #selector(navigationDismiss), for: .touchUpInside)

let leftItem =  UIBarButtonItem(customView: button)

self.navigationItem.leftBarButtonItem = leftItem

}

func navigationDismiss(){

if self.navigationController == nil {

self .dismiss(animated: true, completion: nil)

return

}

if self.navigationController?.viewControllers.count == 1 && (self.navigationController?.viewControllers.last? .isEqual(self))! {

self.dismiss(animated: true, completion: nil)

return

}

//其实是有返回值的

_ = navigationController?.popViewController(animated: true)

}

你可能感兴趣的:(swift导航栏的初始化设置)