1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WebViewでWebページを表示する機能の実装まとめ(Xcode/Storyboard)

Posted at

WKWebViewを使ってWebページの表示の基本的な実装の仕方を記事にしました。

#環境
・Mac Book Pro(macOS:BigSur)
・Xcode(ver:12.5)

#実装例
Unknown-1.gif

#コード例

ViewController.swift

import UIKit
import WebKit

class ViewController: UIViewController,WKNavigationDelegate {
    @IBOutlet weak var webView: WKWebView!
    @IBOutlet weak var indicator: UIActivityIndicatorView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        webView.navigationDelegate = self
        
        let request = URLRequest(url:URL(string: "https://www.google.co.jp/")!)
        
        webView.load(request)
    }

    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        indicator.startAnimating()
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
      
        indicator.stopAnimating()
        indicator.isHidden = true
    
    }
 
}

Webページが表示される前に、indicatorのアニメーションをつけることで表示待ちを表現できます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?