gpt4 book ai didi

ios - 如何在 ViewController 顶部设置标题

转载 作者:行者123 更新时间:2023-11-28 10:46:22 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个 tabBarViewController,这是第一个栏:

class FirstViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
}

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

}

这是自定义类:

class CustomTabBar: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

let firstVC = FirstViewController()
let secondVC = SecondViewController()
let thirdVC = ThirdViewController()

firstVC.tabBarItem.title = "RECENT"
secondVC.tabBarItem.title = "MAP"
thirdVC.tabBarItem.title = "SETTINGS"

firstVC.title = "RECENT"
secondVC.title = "MAP"
thirdVC.title = "SETTINGS"

viewControllers = [firstVC,secondVC,thirdVC]
}

}

所以我的问题是:如何将标题放在 View Controller 的顶部?在之前的代码中我试过了,但它不起作用!

是这样的: enter image description here

最佳答案

title 属性在 View Controller 包装在 UINavigationController 中时显示。这里有一些代码替换了你示例中的最后一行(即 viewControllers 分配),应该可以解决问题:

let firstNC = UINavigationController(rootViewController: firstVC)
let secondNC = UINavigationController(rootViewController: secondVC)
let thirdNC = UINavigationController(rootViewController: thirdVC)
viewControllers = [firstNC,secondNC,thirdNC]

关于ios - 如何在 ViewController 顶部设置标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48389292/

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