项目
在 GitHub 查看
kylehickinson/SwiftUI-WebView
关于
用于使用 WKWebView 的 SwiftUI 组件。
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文WebView
A SwiftUI component View that contains a WKWebView
Since WKWebView handles a lot of its own state, navigation stack, etc, it's almost easier to treat it as a mutable data model. You can set it up prior to how you need it, and then simply use its data within your SwiftUI View's.
Simply spin up a WebViewStore (optionally with your own WKWebView) and use that to access the WKWebView itself as if it was a data model.
Example usage:
import SwiftUI
import WebView
struct ContentView: View {
@StateObject var webViewStore = WebViewStore()
var body: some View {
NavigationView {
WebView(webView: webViewStore.webView)
.navigationBarTitle(Text(verbatim: webViewStore.title ?? ""), displayMode: .inline)
.navigationBarItems(trailing: HStack {
Button(action: goBack) {
Image(systemName: "chevron.left")
.imageScale(.large)
.aspectRatio(contentMode: .fit)
.frame(width: 32, height: 32)
}.disabled(!webViewStore.canGoBack)
Button(action: goForward) {
Image(systemName: "chevron.right")
.imageScale(.large)
.aspectRatio(contentMode: .fit)
.frame(width: 32, height: 32)
}.disabled(!webViewStore.canGoForward)
})
}.onAppear {
self.webViewStore.webView.load(URLRequest(url: URL(string: "https://apple.com")!))
}
}
func goBack() {
webViewStore.webView.goBack()
}
func goForward() {
webViewStore.webView.goForward()
}
}
探索相关项目
加载中…