Want to load local html into UIWebView using swift? Use the below example code to load local html into UIWebView using swift.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @IBOutlet weak var webView: UIWebView! override func viewDidLoad() { super.viewDidLoad() // Adding webView content do { guard let filePath = Bundle.main.path(forResource: "myFile", ofType: "html") else { // File Error print ("File reading error") return } let contents = try String(contentsOfFile: filePath, encoding: .utf8) let baseUrl = URL(fileURLWithPath: filePath) webView.loadHTMLString(contents as String, baseURL: baseUrl) } catch { print ("File HTML error") } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.