2017-07-31 7 views
0

A、B、Cの3つのビューコントローラがあるとします。個々のナビゲーションバーのタイトルカラーの指定方法は? Swift

Aは黒い背景、Bは白、Cは青です。

これらのすべては、移動するのにNavigationControllerBarsを使用します。

どのようにしてプログラム上でnavBarのタイトルの色を変更できますか?私は誰もが、たとえば使用集まってきたものから、

私はAの上に白のタイトルを持つように、Bのため黒、多分C.

用のRed:

navigationController?.navigationBar.titleTextAttributes = [NSForegroundAttributeName: UIColor.white] 

私はに新たなんです迅速に、私にはObj-Cのように見える?

私のために動作しませんし、私は

がエラーとして 'NSForegroundColorAttributeName.rawValue'

で 'NSForegroundColorAttributeName' を置き換え取得しておくこと。

+1

2.3

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] 

NSAttributedStringを使用する方法を学びます。 –

+2

[SwiftでNSMutableAttributedStringを使用して特定のテキストの色を変更する]の可能な複製(https://stackoverflow.com/questions/25207373/changing-specific-texts-color-using-nsmutableattributedstring-in-swift) –

答えて

0

私はこれを私のコードで使用しましたが、問題なくコンパイルしました。

スウィフトスウィフト3

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] 
関連する問題