gpt4 book ai didi

ios - 导航标题颜色变化问题

转载 作者:行者123 更新时间:2023-11-29 11:35:05 25 4
gpt4 key购买 nike

当我弹出 Controller 时,我面对的导航标题颜色没有改变。请找到以下代码。

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以便更好地理解。

最佳答案

这似乎是一个尴尬的问题,其中导航栏的标题属性仅在前进时应用。

在尝试了所有我能做的事情之后,我解决了以下解决方法,我在 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 中提供您的标题,以便在您向前导航时正确设置后退按钮。

关于ios - 导航标题颜色变化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50094290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com