SwiftUI Text: remove link highlighting

Viewed 498

Given the following code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")
                .padding()
            Text("https://lvmh.com")
                .foregroundColor(.black)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

I'm getting the following result:

enter image description here

Desired outcome

  1. Make link color to be the same as the "Hello world" text color
  2. Do not treat the text in the link as a tappable link, treat it just as a regular text.

Follow-up question

I'd like to apply the same behavior to the email strings, e.g.:

Text("r.topchii@corp.lvmh.com")

Should not be highlighted.

1 Answers

Solution: use Text(verbatim: ):

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")
                .padding()
            Text(verbatim: "https://lvmh.com")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

The result looks as follows:

enter image description here

Also solves the problem with the emails:

enter image description here

Related