本文介绍了如何更改navigationitem标题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为整天都要更改导航栏标题颜色,但它不起作用。这是我的代码:

  var user:User? {
didSet {
navigationItem.title = user?.name

observeMessages()
}
}

我使用didSet在导航标题上显示标题。

解决方案

在代码中添加此项。 。

 让textAttributes = [NSForegroundColorAttributeName:UIColor.red] 
navigationController?.navigationBar.titleTextAttributes = textAttributes

SWIFT 4:

  let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.red] 
navigationController?.navigationBar.titleTextAttributes = textAttributes


I think all day to change the navigation Bar title color, but it doesn't work. this is my code:

var user: User? {
    didSet {
        navigationItem.title = user?.name

         observeMessages()
    }
}

I use didSet to show the title on the navigation title.

解决方案

Add this in your code . .

let textAttributes = [NSForegroundColorAttributeName:UIColor.red]
navigationController?.navigationBar.titleTextAttributes = textAttributes

SWIFT 4:

let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.red]
navigationController?.navigationBar.titleTextAttributes = textAttributes

这篇关于如何更改navigationitem标题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:38