Created
September 23, 2017 21:36
-
-
Save nicktesla2011/085490055ecd60afdb35805b788da4c2 to your computer and use it in GitHub Desktop.
WKWebView View Controller for Xcode 9.0/Swift 4/iOS11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 | |
} | |
} |
THANKS!!!
Hi, how to use Activity Indicator View with page loading? Thanks! :)
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
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
then what if the url destination in the form of a link to the website?