Recently introduced in WWDC 2020, Link is text with a link within it. When you press it, you will be redirected to the link you have attached within.

Bear in mind that this is only supported in iOS 14 and above and can only be used in Xcode 12+.


Prerequisites

To follow along with this tutorial, you’ll need a basic familiarity with Swift and some basic knowledge in at least Xcode 12+.


Link

The basic usage of Link is to declare its title and URL, and you are good to go.

Link("Facebook", destination: URL(string: "https://www.facebook.com")!)

I was actually expecting a WebView to pop up within it, but instead, it exits and opens the link on Safari.


Link Customisation

It’s rather easy to customise the Link where you tweak it with some colors or even fonts.

Link("Facebook", destination: URL(string: "https://www.facebook.com")!)
    .font(.largeTitle)
    .foregroundColor(.blue)

Including an image with the text is also a rather straightforward process.

Link(destination: URL(string: "https://www.facebook.com")!, label: {
    Text("Facebook")
    Image("facebook")
        .resizable()
        .frame(width: 30, height: 30)
})

If you would like a standalone image, simply remove the text and you will only see an image. By clicking on the image, you will be redirected to the link.

#swiftui #ios #xcode #programming #swif

Introducing Link in SwiftUI
7.05 GEEK