打开网页的操作 发短信等

打开网页 现在main.storyboard中添加一个按钮 随后为其关连事件,当按下这个按钮时,跳转界面到网页

import UIKit

class ViewController: UIViewController {

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

    @IBAction func tiaozhuan(sender: UIButton) {
        //打开网页的代码
    UIApplication.sharedApplication().openURL(NSURL(string: "http://www.baidu.com")!)
    }

}

实质上都是遵守协议 一个是http的协议 发短信是sms的协议 电话是tel的协议 发邮件是mailto 的协议

import UIKit

class ViewController: UIViewController {

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

    @IBAction func tiaozhuan(sender: UIButton) {
        //打开网页的代码
    UIApplication.sharedApplication().openURL(NSURL(string: "tel:\\10086")!)
    }

}
import UIKit

class ViewController: UIViewController {

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

    @IBAction func tiaozhuan(sender: UIButton) {
        //打开网页的代码
    UIApplication.sharedApplication().openURL(NSURL(string: "sms:\\10086")!)
    }

}
发邮件

import UIKit

class ViewController: UIViewController {

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

    @IBAction func tiaozhuan(sender: UIButton) {
        //打开网页的代码
    UIApplication.sharedApplication().openURL(NSURL(string: "mailto:\\10086")!)
    }

}




你可能感兴趣的:(打开网页的操作 发短信等)