How to create tappable url/phone number in SwiftUI

前端 未结 6 1359
Happy的楠姐
Happy的楠姐 2021-01-04 10:06

I would like to display a phone number in a SwiftUI Text (or any View), and then make it clickable so that it will open the \'Phone\'.

Is there a way to do this with

6条回答
  •  情书的邮戳
    2021-01-04 10:46

    From iOS 14, Apple provides us a Link view by default. So, you can just use this,

    Link("Anyone can learn Swift", destination: URL(string: "https://ohmyswift.com")!)
    

    For the previous versions of iOS, like iOS 13.0, you still have to use

    Button("Anyone can learn Swift") {
       UIApplication.shared.open(URL(string: "https://ohmyswift.com")!)
    }
     
    

提交回复
热议问题