Button with link to a website

Asked

Viewed 198 times

0

Could you help me make a button with a link to a website? It’s an iPhone app and I’d like you to press a button and open the site in Safari (for example).

  • how do I do? I did the butao but do not know what to do now

  • 1

    And what do you want to do? What behavior do you expect this button to have? You can [Dit] your question and include more information. By the way, make a tour and better understand how Stackoverflow works, welcome.

  • I’ve already made my point

  • 1

    You mentioned that you already made the button, could edit your question and include the button code in it?

  • the boot I made was just create a boot nothing else, I did no code

  • Take a look at this link @Brunogonçalves , E this link also

  • how I create an Ibaction?

Show 2 more comments

2 answers

0

The function for this is the openURL, an example:


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

    I’ve solved thank you (:

  • If you already solved please edit your question or create an answer telling how you solved the problem.

0

Another approach would be to use the SFSafariViewController, it opens safari without leaving your app. This greatly improves the usability of the App.

First, in your Viewcontroller, import the SafariServices. And use the SFSafariViewController as follows:

if let url = URL(string: "http://...") {
    let safariViewController = SFSafariViewController(url: url)
    present(safariViewController, animated: true)
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.