使超链接按钮斯威夫特 [英] Make button hyperlink Swift

查看:186
本文介绍了使超链接按钮斯威夫特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的快捷,因为它是一个相当新的编程语言没有它多文档。
我试图让一个按钮作为一个超链接。我已经创建了一个IBAction为,但我不知道从哪里里去。这里是我的code:

 进口的UIKit一流的ViewController:UIViewController的{
@IBAction FUNC的WebLink(发件人:AnyObject){}覆盖FUNC viewDidLoad中(){
    super.viewDidLoad()
    //装载视图,通常从笔尖后做任何额外的设置。
}覆盖FUNC didReceiveMemoryWarning(){
    super.didReceiveMemoryWarning()
    可以重新创建任何资源的处置//。
}
}


解决方案

您可以通过调用UIApplication的实例的OpenURL 方法打开网址:

  @IBAction FUNC的WebLink(发件人:AnyObject){
    如果让URL = NSURL(串:HTTP:// ......){
        UIApplication.sharedApplication()的OpenURL(URL)
    }
}

I am using swift and as it is a fairly new programing language there is not much documentation on it. I am trying to make a button act as a hyperlink. I have created an IBAction but I do not know where to go from there. Here is my code:

import UIKit

class ViewController: UIViewController {


@IBAction func WebLink(sender: AnyObject) {

}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

解决方案

You can open a URL by calling the openURL method on the UIApplication instance:

@IBAction func WebLink(sender: AnyObject) {
    if let url = NSURL(string: "http://...") {
        UIApplication.sharedApplication().openURL(url)
    }
}

这篇关于使超链接按钮斯威夫特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆