Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Text: remove link highlighting

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("[email protected]")

Should not be highlighted.

like image 803
Richard Topchii Avatar asked Oct 15 '25 19:10

Richard Topchii


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

like image 137
Richard Topchii Avatar answered Oct 17 '25 11:10

Richard Topchii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!