cbe*_*r84 17
iOS < 13
Button(action: {
self.someState.toggle()
if let url = URL(string: "https://www.hackingwithswift.com") {
UIApplication.shared.open(url)
}
}) {
Text("some label")
}
Run Code Online (Sandbox Code Playgroud)
iOS > 14
Link("My new Link", destination: URL(string: "https://www.mylinkcom")!)
Run Code Online (Sandbox Code Playgroud)
在视图中:
@Environment(\.openURL) private var openURL
Run Code Online (Sandbox Code Playgroud)
稍后,例如按下按钮时:
guard let url = URL(string: urlString) else { return }
openURL(url)
Run Code Online (Sandbox Code Playgroud)
了解更多: https: //developer.apple.com/documentation/swiftui/openurlaction
| 归档时间: |
|
| 查看次数: |
3951 次 |
| 最近记录: |