casillas
casillas

Reputation: 16813

tabBarController navigationItem.title color

I am setting the title as follows, but I want to change the color of the text as well, but there is no textattributes, I wonder how it can be done ?

self.tabBarController?.navigationItem.title = "Settings"

I tried the following as well, but it did not even show the label.

let navLabel = UILabel()
let navTitle = NSMutableAttributedString(string: "Settings", attributes:[
       NSAttributedString.Key.foregroundColor: UIColor.blue,
       NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17.0, weight: UIFont.Weight.light)])

navLabel.attributedText = navTitle
self.tabBarController?.navigationItem.titleView = navTitle

Upvotes: 1

Views: 258

Answers (2)

Yan.Zhao
Yan.Zhao

Reputation: 73

The size of label is right ? Call fitThatSize

Upvotes: 0

AtulParmar
AtulParmar

Reputation: 4570

try this code, I hope it helps you.

Build Settings\Swift Language Version: 4.1

General\Deployment Target: 10.3

let attrsNormal = [NSAttributedStringKey.foregroundColor : UIColor.black,
                 NSAttributedStringKey.font : UIFont(name: "Arial", size: 14)!]
    UITabBarItem.appearance().setTitleTextAttributes(attrsNormal,
                                                     for: UIControlState.normal)

Upvotes: 2

Related Questions