单击 uibutton 时使用应用程序调用
Call using an app when uibutton is clicked
我有一个显示电话号码的应用程序,该号码位于 uibutton 中。单击按钮时,我希望它调用。最好的方法是什么?
从按钮中获取文本到 NSUrl 中并传入:
let url = NSURL(string: button.currentTitle)
UIApplication.sharedApplication().openURL(url)
如果调用按钮的选择器时,它会将按钮传递给方法。所以你可以从那里抓住它。
func buttonTapped(sender: AnyObject) {
if let button : UIButton = sender as? UIButton {
if let url = NSURL(string: button.titleLabel?.text) {
UIApplication.sharedApplication().openURL(url)
}
}
}
我有一个显示电话号码的应用程序,该号码位于 uibutton 中。单击按钮时,我希望它调用。最好的方法是什么?
从按钮中获取文本到 NSUrl 中并传入:
let url = NSURL(string: button.currentTitle)
UIApplication.sharedApplication().openURL(url)
如果调用按钮的选择器时,它会将按钮传递给方法。所以你可以从那里抓住它。
func buttonTapped(sender: AnyObject) {
if let button : UIButton = sender as? UIButton {
if let url = NSURL(string: button.titleLabel?.text) {
UIApplication.sharedApplication().openURL(url)
}
}
}