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)

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容