How to create tappable url/phone number in SwiftUI

前端 未结 6 1312
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:44

    Try this,

    let strNumber = "123-456-7890"
    
    Button(action: {
        let tel = "tel://"
        let formattedString = tel + strNumber 
        guard let url = URL(string: formattedString) else { return }
        UIApplication.shared.open(url) 
       }) {
       Text("123-456-7890")
    }
    

提交回复
热议问题