UINavigationBar Text Color in Swift

前端 未结 11 1641
刺人心
刺人心 2021-01-30 12:20

How would I go about changing the color of the UINavigationBar in Swift?

Most things online say to do something like:

[self.navigationContro         


        
相关标签:
11条回答
  • 2021-01-30 13:17

    Use NSForegroundColorAttributeName as key, not "NSForegroundColorAttributeName" string.

    let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    self.navigationController.navigationBar.titleTextAttributes = titleDict
    
    0 讨论(0)
  • 2021-01-30 13:18
        //Nav Bar Title
        self.title = "WORK ORDER"
        self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
    
    0 讨论(0)
  • 2021-01-30 13:20

    Swift 3

    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.white], for: .selected)
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.black], for: .normal)
    
    0 讨论(0)
  • 2021-01-30 13:20

    Swift 4.x:

    UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    
    0 讨论(0)
  • 2021-01-30 13:21

    Swift 2.0

    self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
    
    0 讨论(0)
提交回复
热议问题