gpt4 book ai didi

ios - 当我没有引用时,如何使用/编辑导航栏功能?

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

我目前正在学习 iOS 开发,但我很困惑如何在没有 IBOutlet 的情况下编辑/使用导航栏?

代码:

class ChatViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var messageTextfield: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
title = "⚡️FlashChat" //edited the title of the navigation bar for this view
navigationItem.hidesBackButton = true //hid a button

}

@IBAction func sendPressed(_ sender: UIButton) {
}

@IBAction func logoutPressed(_ sender: UIBarButtonItem) {
do {
try Auth.auth().signOut()
navigationController?.popToRootViewController(animated: true)
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}

}

}

最佳答案

调用setupNavBarAttributes()来自 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool 的函数位于 Appdelegate.swift 文件中并观察更改。

它将自定义应用程序中每个 UIViewControllerUINavigationBar

func setupNavBarAttributes() {

UINavigationBar.appearance().barStyle = .default
UINavigationBar.appearance().tintColor = .cyan // change color of the buttons of navigationbar
UINavigationBar.appearance().barTintColor = .blue // change front color of navigationbar
UINavigationBar.appearance().backgroundColor = .clear
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().shadowImage = UIImage() // make disappear the bottom shadow of navigationbar
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default) // make background to a blank/empty image

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 19, weight: .bold)] // change the font color of navigation title

}

关于ios - 当我没有引用时,如何使用/编辑导航栏功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59152457/

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