Appleguy15 Appleguy15 - 11 days ago 5
Swift Question

Make button hyperlink Swift

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.
}


}

Answer

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)
    }
}
Comments