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.

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.