Zorgan
Zorgan

Reputation: 9173

How to underline a Link in SwiftUI?

Here is my link:

Link("Terms + Conditions", destination: URL(string: "https://my.app/terms_and_conditions.html")!)

I'm aware that Text() has an underline() modifier, however there doesn't seem to be one for Link().

Any idea?

Upvotes: 10

Views: 6893

Answers (1)

Vlad
Vlad

Reputation: 1051

Link has an initialiser that takes a label argument: init(destination: URL, label: () -> Label)

So for your example, you would need to set up a Text("Terms + Conditions") view as the label, and use the .underline() modifier on the text view to get the intended outcome.

Using Apples website as an example:

Link(destination: URL(string: "https://www.apple.com")!, label: {
    Text("Apple")
        .underline()
})

Upvotes: 28

Related Questions