Search code examples
iosswifttextswiftui

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.


Solution

  • 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