13

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?

Iker Solozabal
  • 1,232
  • 11
  • 16

2 Answers2

23

It is possible to use accent color, like

Text(.init("[Link Example](https://www.google.es/)"))
    .accentColor(.red)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690
14

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)
Oluwatobi Omotayo
  • 1,719
  • 14
  • 28
  • 1
    doesn't work too – Peter Lapisu Feb 22 '23 at 13:48
  • The best way would be to use an `AttributedString` in `Text`, and define the `foregroundColor` on the range of the text where the link is added. Refer to this [question](https://stackoverflow.com/questions/71446034/how-to-change-hyper-link-text-color-in-swiftui) – Crazed'n'Dazed May 03 '23 at 05:44