如何在 Swift 4 中将 navigationItem.title 更改为白色?

Posted

技术标签:

【中文标题】如何在 Swift 4 中将 navigationItem.title 更改为白色?【英文标题】:How do I change the navigationItem.title to the color white in Swift 4? 【发布时间】:2018-05-27 16:12:29 【问题描述】:

let uid = Auth.auth().currentUser?.uid
Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: (snapshot) in          
    if let dictionary = snapshot.value as? [String: AnyObject] 
        self.navigationItem.title = dictionary["name"] as? String
        self.navigationController?.navigationBar.prefersLargeTitles = true
    
,withCancel: nil)

【问题讨论】:

【参考方案1】:

您可以使用以下方法更改标题颜色:

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]

【讨论】:

“MessagesController”类型的值没有成员“navigationBar” @JamaBarons:我已经更新了我的答案。请检查。 它现在可以构建,但文本仍然是黑色的 还有其他建议吗?老实说,我不确定它可能是什么。【参考方案2】:
self.navigationController?.navigationBar.tintColor = .white

【讨论】:

以上是关于如何在 Swift 4 中将 navigationItem.title 更改为白色?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Swift 4 中将 navigationItem.title 更改为白色?

如何在 Swift 4 中将 Encodable 或 Decodable 作为参数传递?

如何在Swift 4中将UIImage转换为字节数组

如何在 Swift 4.0 中将 JSON 输出设置为 UILabel?

如何在swift 4中将按钮放在表格视图控制器的前面? [复制]

如何在 swift 4 iOS 中将 Callkit 与 Agora VOiP 集成?