BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Setting the color of navigation title to accentColor

Forums > SwiftUI

Hi there,

I found a way to set the color of my navigation bars to the accent color. But I want to know if this is the only viable way and there is no SwiftUI solution?

This is what I found (and what works). I use this in my first view and the color is inherited to any view below in the hierarchy (which is what I want).

init() {
        //Use this if NavigationBarTitle is with Large Font
        UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor(.accentColor)]
        //Use this if NavigationBarTitle is with displayMode = .inline
        UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor(.accentColor)]
    }

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.