Skip to content

Instantly share code, notes, and snippets.

@ioniacob
Forked from nicktesla2011/ViewController.swift
Created February 7, 2018 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioniacob/8a5e40851114fae2cac2a59e5a15e287 to your computer and use it in GitHub Desktop.
Save ioniacob/8a5e40851114fae2cac2a59e5a15e287 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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment