WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Is there a way to style the navigation link?

Forums > SwiftUI

I am trying to style the navigation Link button in SwiftUI right now it's the standard blue but I am trying to get it to Black and Bold similar to that of Fitness+ but the problem I encounter based on all the research I have done is finding a solution to the problem.

I hope someone can guide me.

Best, Imran

   

Not sure what you want but add .modifliers to want you want.

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink {
                Text("New View")
            } label: {
                Text("Tapped Me")
            }
            .padding()
            .background(.black)
            .foregroundColor(.white)
            .font(.headline)
            .cornerRadius(10)
        }
    }
}

.buttonStyle also works

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink {
                Text("New View")
            } label: {
                Text("Tapped Me")
            }
            .buttonStyle(.borderedProminent)
        }
    }
}

   

I am trying to change the colour of the nagivation link text. For example, on fitness+ if you click HIIT the back button is black, how do you do that on the navigation link? These modifiers don't change the colour of my navigation link it's still blue.

   

Using

.accentColour(Color.black) 

on the navigation view is what made the navigation link black.

   

Sorry You want the Colors in the Navigation Bar to be different color.

Then goto to the Asserts file and you will see AccentColor change this to the color you want in App struct use .tint(.accentColor). See below

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .tint(.accentColor)
        }
    }
}

PS .accentColour has been depreciated.

   

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

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.