gpt4 book ai didi

ios - 如何在添加为更多导航 Controller 的导航 Controller 上设置标题

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

我有 6 个 View Controller ,并且正在使用 UiTabbar View 。因此,在主屏幕上,选项卡中显示了 4 个 View Controller 的数量,操作系统创建了另一个 View Controller 并将其命名为 more。

单击“更多”后,它向我显示了 UiTableView 内的 2 个 View Controller 。当我单击它们时,它会打开我的 View Controller ,其顶部有导航 Controller ,后退按钮标记为“更多”

完整理解见下图 enter image description here

What I Want: Here you can see that More is just visible with the Back button, I want to only show the Back button and I want center title with the label of "Offers" in white text

更新1:

Calling this method in ViewWillDisplay()

    func setUpNavBar(title: String,backBtn : String) -> Void {


let backButton = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil)
navigationItem.backBarButtonItem = backButton

navigationController?.navigationBar.tintColor = UIColor.white

let titleStr = title

self.navigationItem.title = titleStr
self.navigationItem.titleView?.backgroundColor = UIColor.red


let titleLabel = UILabel()
titleLabel.textColor = .white
titleLabel.text = titleStr
self.navigationItem.titleView = titleLabel



self.navigationController?.navigationBar.barTintColor = CommonUtils.hexStringToUIColor(hex: AppColor.colorTwentyScaleDarkerOfColorPrimaryDark)

if var textAttributes = navigationController?.navigationBar.titleTextAttributes {
textAttributes[NSAttributedString.Key.foregroundColor] = UIColor.white
navigationController?.navigationBar.titleTextAttributes = textAttributes
}
}

最佳答案

在 OffersViewController 中:

override func viewWillAppear(_ animated: Bool) {
self.title = "Offers"
}

在之前的ViewController中

    override func viewWillDisappear(_ animated: Bool) {
self.title = ""
}


您也可以尝试这个:

override func viewWillAppear(_ animated: Bool) {
let titleLabel = UILabel()
titleLabel.textColor = .white
titleLabel.text = self.title
self.navigationItem.titleView = titleLabel
}

关于ios - 如何在添加为更多导航 Controller 的导航 Controller 上设置标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59322112/

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