Questions tagged [swiftui-link]

SwiftUI's Link is a control for navigating to a URL. Create a link by providing a destination URL and a title. The title tells the user the purpose of the link, and can be a string, a title key that produces a localized string, or a view that acts as a label.

Example Usage

The example below creates a link to example.com and displays the title string as a link-styled view:

Link("View Our Terms of Service",
      destination: URL(string: "https://www.example.com/TOS.html")!)

Alternatively, you can override the default behavior by setting the openURL environment value with a custom OpenURLAction:

Link("Visit Our Site", destination: URL(string: "https://www.example.com")!)
    .environment(\.openURL, OpenURLAction { url in
        print("Open \(url)")
        return .handled
    })

Click here to see the full documentation.

3 questions
2
votes
1 answer

SwiftUI Link Long Text Alignment Multiline

Problem I'm using SwiftUI's Link to open Safari from the application. But I have a long text for the link. For now, the second line of the text always keeps aligned at the center. What I want I want to be able to use leading TextAlignment with…
MGY
  • 7,245
  • 5
  • 41
  • 74
0
votes
1 answer

SwiftUI - Make entire width of a button in a section clickable, not just text

I am trying to make a Log Out button inside a List with sections. However, when I add the button to the section, only the "Log Out" text is clickable and not the entire section. I don't want to resize it to anything larger than the current section…
0
votes
2 answers

Why are my SwiftUI Links not respecting frame maxWidth?

I am trying to make a list of buttons/links that all have the same width, regardless of text content. Unfortunately, it seems like the Link() items do not respect the .frame(maxWidth) settings and just do whatever they want. I cannot find any…