skip to Main Content

I am building a Swift app and I am trying to change the color of the navigation bar.
I’m trying to do it directly from Xcode without code on the main.storyboard.

I’ve tried changing several settings in the Xcode Attribute Inspector but nothing has worked. I’ve also searched StackOverFlow but all the answers I find are are changing it programatically.

Does anyone know how to change the color of it directly from the Attribute Inspector?

Thanks.

5

Answers


  1. Try it:

       if #available(iOS 13.0, *) {
                    let appearance = UINavigationBarAppearance()
                    appearance.configureWithOpaqueBackground()
                    appearance.backgroundColor = UIColor(red: 21/255, green: 46/255, blue: 82/255, alpha: 1)
                    appearance.titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont(name: "Arial", size: 32)!]
                    navigationController?.navigationBar.standardAppearance = appearance
                    navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
                    navigationController?.navigationBar.compactAppearance = appearance.copy()
    }
    
    Login or Signup to reply.
  2. You can use

    navigationBar.barTintColor = UIColor.whiteColor()
    

    or you do this by Storyboard Like this.

    enter image description here

    Login or Signup to reply.
  3. In the storyboard, change the background color. It will work.

    enter image description here

    Login or Signup to reply.
  4. You just need to click on the navbar and in attribute inspector, there is an option for Background, you can provide any color which you want to give. In my case, I selected a custom sky blue color.
    Check Screenshot here

    Login or Signup to reply.
  5. 💡 Navigation Bar:

    navigationController?.navigationBar.barTintColor = UIColor.green
    

    Replace greenColor with whatever UIColor you want

    💡 Navigation Bar Text:

    navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.orange]
    

    Replace orangeColor with whatever color you like.

    💡 Tab Bar:

    tabBarController?.tabBar.barTintColor = UIColor.brown
    

    💡 Tab Bar Text:

    tabBarController?.tabBar.tintColor = UIColor.yellow
    

    On the last two, replace brownColor and yellowColor with the color of your choice.

    💡swift navigation bar title color:

    Place this in your didFinishLaunchingWithOptions method in the AppDelegate.

    let attrs = [
      NSAttributedString.Key.foregroundColor: UIColor.white
    ]
    
    UINavigationBar.appearance().titleTextAttributes = attrs
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search