Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to underline a Link in SwiftUI?

Tags:

ios

swift

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?

like image 923
Zorgan Avatar asked Dec 30 '22 21:12

Zorgan


1 Answers

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()
})
like image 56
Vlad Avatar answered Jan 09 '23 09:01

Vlad