Iker Solozabal
Iker Solozabal

Reputation: 1402

Change Text link color swiftUI

I have the folowing Text() that takes markdown to show a link

Text(.init("[Link Example](https://www.google.es/)"))

Example of my text

Is there a way of changing the default color set to the link?

Upvotes: 21

Views: 10119

Answers (4)

koen
koen

Reputation: 5729

Another solution using Link (iOS 14+):

if let url = URL(string: "https://www.google.es/" {
   Link(destination: url) {
      Text("Link Example")
         .foregroundColor(Color(.label))
   }
}

Upvotes: 1

Abhijith
Abhijith

Reputation: 3394

Link color is the default accent color of the app which is blue.

You can change this by setting a custom accent color:

  1. Add a color set in your Assets.xcassets

  2. In target -> Build settings, search for "Global Accent Color Name"

  3. Double click on it and set the color name aded in step 1

Thats it..!

Upvotes: 0

Asperi
Asperi

Reputation: 257653

It is possible to use accent color, like

Text(.init("[Link Example](https://www.google.es/)"))
    .accentColor(.red)

Upvotes: 35

Oluwatobi Omotayo
Oluwatobi Omotayo

Reputation: 1879

You can achieve that with .tint(_:) as accentColor(_:) will soon be deprecated according to the documentation.

Text("[Link Example](https://www.google.es/)")
  .tint(Color.red)

Upvotes: 21

Related Questions