WebViewTest.swift
import SwiftUI
import WebKit //WebKitをインポート
struct WebViewTest: UIViewRepresentable {
// var url: String = "https://google.com" //表示するWEBページのURLを指定
func makeUIView(context: Context) -> WKWebView{
return WKWebView()
}
func updateUIView(_ uiView: UIViewType, context: Context) {
guard let path: String = Bundle.main.path(forResource: "index", ofType: "html") else { return }
let localHTMLUrl = URL(fileURLWithPath: path, isDirectory: false)
uiView.loadFileURL(localHTMLUrl, allowingReadAccessTo: localHTMLUrl)
}
}
///////////////////////////
ContentView.swift
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: WebViewTest()) {
Text("Show web page")
}
}
// WebViewTest()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
//////////////////////////////
index.html