//
// ContentView.swift
// webview-app
//
// Created by 夏凌晨 on 2020/10/27.
// Copyright 2020 webgeeker. All rights reserved.
//
import SwiftUI
struct ContentView: View {
var body: some View {
// Text("Hello, World!");
// SwiftUI_WKWebView(url: "https://cdn.xgqfrms.xyz");
SwiftUI_WKWebView(url: "https://cdn.xgqfrms.xyz")
.edgesIgnoringSafeArea(Edge.Set.top)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
/*
// SwiftUI_WKWebView(url: "https://cdn.xgqfrms.xyz");
no need ;
CompileDylibError: Failed to build ContentView.swift
Compiling failed: ';' statements are not allowed
*/
//
// SwiftUI_WKWebView.swift
// webview-app
//
// Created by 夏凌晨 on 2020/10/28.
// Copyright 2020 webgeeker. All rights reserved.
//
import SwiftUI
//import Foundation
import WebKit
struct SwiftUI_WKWebView: UIViewRepresentable {
var url: String;
func makeUIView(context: Context) -> WKWebView {
guard let url = URL(string: self.url) else {
return WKWebView();
}
let request = URLRequest(url: url);
let webview = WKWebView();
webview.load(request);
return webview;
}
func updateUIView(_ uiView: WKWebView, context: Context) {
//
}
}
//
// SwiftUI_WKWebView.swift
// webview-app
//
// Created by 夏凌晨 on 2020/10/28.
// Copyright 2020 webgeeker. All rights reserved.
//
import SwiftUI
//import Foundation
import WebKit
struct SwiftUI_WKWebView: UIViewRepresentable {
var url: String
func makeUIView(context: Context) -> WKWebView {
guard let url = URL(string: self.url) else {
return WKWebView()
}
let request = URLRequest(url: url)
let webview = WKWebView()
webview.load(request)
return webview
}
func updateUIView(_ uiView: WKWebView, context: Context) {
//
}
}
// Previews 入口
struct SwiftUI_WKWebView_Previews: PreviewProvider {
static var previews: some View {
// 联网的 URL, Canvas 必须开启 live preview, 动态的请求内容
SwiftUI_WKWebView(url: "https://cdn.xgqfrms.xyz")
.edgesIgnoringSafeArea(Edge.Set.top)
}
}
/*
// SwiftUI_WKWebView(url: "https://cdn.xgqfrms.xyz");
no need ;
CompileDylibError: Failed to build ContentView.swift
Compiling failed: ';' statements are not allowed
*/
https://gist.github.com/xgqfrms/71a6f7471b79905fb53147b23805d382
https://www.youtube.com/watch?v=C5xxrCj8LC0
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
手机扫一扫
移动阅读更方便
你可能感兴趣的文章