当我弹出控制器时,我面临的导航标题颜色没有改变。请找到下面的代码。
ProfilescreenVC.swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.barTintColor = UIColor.primaryGreen
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
self.navigationController?.navigationBar.titleTextAttributes = textAttributes
}
编辑profileVC.swift
override func viewDidLoad() {
super.viewDidLoad()
self.style()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func style() {
navigationController?.navigationBar.tintColor = UIColor.black
navigationController?.navigationBar.barTintColor = UIColor.white
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
navigationController?.navigationBar.titleTextAttributes = textAttributes
carbonTabSwipeNavigation.setIndicatorColor(UIColor.black)
carbonTabSwipeNavigation.setTabBarHeight(50.0)
carbonTabSwipeNavigation.setNormalColor(UIColor.hexString("9A9CA1"), font: UIFont.systemFont(ofSize: 15))
carbonTabSwipeNavigation.setSelectedColor(UIColor.black, font: UIFont.systemFont(ofSize: 15))
self.navigationController?.view.setNeedsLayout()
self.navigationController?.view.layoutIfNeeded()
}
override func viewDidDisappear(_ animated: Bool) {
navigationController?.navigationBar.tintColor = UIColor.white
navigationController?.navigationBar.barTintColor = UIColor.white
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
navigationController?.navigationBar.titleTextAttributes = textAttributes
super.viewDidDisappear(animated)
}
我遇到标题颜色更改的问题,请检查以下内容video https://file.fm/u/skw8j45v#/为了更好的理解。
这似乎是一个尴尬的问题,其中导航栏的标题属性只能向前应用。
在尝试了一切之后,我解决了以下解决方法,我在 navigationItem 中提供了自己的 titleView。
let titleView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
titleView.backgroundColor = UIColor.clear
let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
titleLabel.textAlignment = .center
titleLabel.text = "Profile"
titleLabel.textColor = .white
titleView.addSubview(titleLabel)
self.navigationItem.titleView = titleView
self.navigationItem.title = "Profile"
请注意,您还需要在 navigationItem.title 中提供标题,以便在向前导航时正确设置后退按钮。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)