swiftui
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.
最近在WWDC 2020中引入的
Link
是带有
Link
的文本。 当您按下它时,您将被重定向到您附加在其中的链接。
Bear in mind that this is only supported in iOS 14 and above and can only be used in Xcode 12+.
请记住,此功能仅在iOS 14及更高版本中受支持,并且只能在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+.
要继续学习本教程,您需要对Swift有基本的了解,并且至少在Xcode 12+中具有一些基本知识。
链接
(
Link
)
The basic usage of
Link
is to declare its title and URL, and you are good to go.
Link
的基本用法是声明其标题和URL,您可以使用。
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.
我实际上期望WebView在其中弹出,但是相反,它退出并打开Safari上的链接。
链接定制
(
Link Customisation
)
It’s rather easy to customise the
Link
where you tweak it with some colors or even fonts.
在某些颜色或字体进行微调的地方自定义
Link
很容易。
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.
如果您想要一个独立的图像,只需删除文本,您将只看到一个图像。 通过单击图像,您将被重定向到链接。
翻译自:
https://medium.com/better-programming/introducing-link-in-swiftui-383076e335b8
swiftui