Skip to content

Instantly share code, notes, and snippets.

@nicktesla2011
Created September 23, 2017 21:36
Show Gist options
  • Save nicktesla2011/085490055ecd60afdb35805b788da4c2 to your computer and use it in GitHub Desktop.
Save nicktesla2011/085490055ecd60afdb35805b788da4c2 to your computer and use it in GitHub Desktop.
WKWebView View Controller for Xcode 9.0/Swift 4/iOS11
//
// ViewController.swift
// Honk
//
// Created by Nick Gressle on 9/23/17.
// Copyright © 2017 nick gressle illustrations llc. All rights reserved.
//
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let webView = WKWebView()
let htmlPath = Bundle.main.path(forResource: "Honk", ofType: "html")
let folderPath = Bundle.main.bundlePath
let baseUrl = URL(fileURLWithPath: folderPath, isDirectory: true)
do {
let htmlString = try NSString(contentsOfFile: htmlPath!, encoding: String.Encoding.utf8.rawValue)
webView.loadHTMLString(htmlString as String, baseURL: baseUrl)
} catch {
// catch error
}
webView.navigationDelegate = self
view = webView
}
}
@szpuk
Copy link

szpuk commented Feb 11, 2018

Hi, how to use Activity Indicator View with page loading? Thanks! :)

@Knorzew
Copy link

Knorzew commented Aug 4, 2018

Hello
I'd like to make a webapp of a hypedocument. ...

When using

25 webView.navigationDelegate = #self

on XCode 9.2 the word self is red underlined and I get an errormessage
"Cannot assign value of type 'ViewController' to type 'WKNavigationDelegate?'"

What can I do?

Best Andreas

@chemory
Copy link

chemory commented Oct 25, 2018

You are a lifesaver.... I have scoured the web looking for something I could make sense of and this is brilliant. Worked perfectly - thank you :)

I have one question - how would I make the views scrollable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment