Link – SwiftUI Reference Guide

preview_player
Показать описание

The title tells the user the purpose of the link. This can be a string, a button, or a custom view that acts as a label.

When a user taps or clicks a Link, the default behavior depends on the contents of the URL and its associated application.

Links were designed for the web, but we can add them to our applications and let the system decide where to open the linked document.

For example, a SwiftUI Link can trigger to call a phone number, open the default email client, or other apps that Apple provides schemes for.

Customization.

As with other views, we can style links using standard view modifiers depending on the view type of the link’s label.

For example, a text label could be modified with a font or foreground color modifier to customize the appearance.

Alternatively, we can add the same styling options that we also use on buttons.

Just like button style: bordered.

Then, button border shape: capsule.

Different control sizes or tint colors.

Custom Link View

Also, there is another initializer we can use to create a custom button-like view for the Link.

To use this new link initializer, we need to put the destination parameter first, and then we can create and customize any view that users can tap on to navigate to a URL.

In this example, we created a well noticeable stylized view with a system symbol and a text view wrapped into a horizontal view container.

CHAPTERS

00:00 SwiftUI Link
00:33 Link URL
00:51 Custom Link
01:19 Link View

This SwiftUI tutorial is part of the best online SwiftUI Masterclass course.

This 4K tutorial is part of the bestseller SwiftUI Masterclass course with more than 30 thousand students at the Credo Academy.

#SwiftUI #CredoAcademy #iOSDevelopment
Рекомендации по теме
visit shbcf.ru