如何在添加为更多导航控制器的导航控制器上设置标题

我有6个视图控制器,并且正在使用UiTabbar视图。因此,在主屏幕中,选项卡中显示4个ViewController的数量,OS创建另一个ViewController,并将其命名为more。

点击更多,它向我展示了UiTableView内部的视图控制器2。当我单击它们时,它会打开我的viewcontroller,其顶部的Navigation控制器带有标记为More的后退按钮

为全面了解,请参见下图

如何在添加为更多导航控制器的导航控制器上设置标题

  

我想要的内容:在这里您可以看到“返回”按钮仅显示更多内容,我只想显示“返回”按钮,并希望居中   标题,标签为“要约”,白色文本

更新1:

  

在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
    }
}
xiaoyan198607 回答:如何在添加为更多导航控制器的导航控制器上设置标题

在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
}
,

通常,这是在视图控制器上加载了视图的情况下完成的:

UNION
本文链接:https://www.f2er.com/2927326.html

大家都在问