present SFSafariViewController 顯示網頁

練習使用SFSafariViewController,Safari有一個好處是不用自己加入上一頁&下一頁,跟webView比起來好用多了~!


程式碼

import UIKit
import SafariServices
//ㄑ匯入SafariServices
class ViewController: UIViewController, SFSafariViewControllerDelegate {
@IBAction func buttonPressed(_ sender: UIButton) {
if let url = URL(string: “https://medium.com/"){
let safari = SFSafariViewController(url: url)
safari.delegate = self
present(safari, animated: true, completion: nil)
}
}