swift 如何在页面加载时显示图像?
How to show image while page is loading in swift?
我是 swift 和 Xcode 的初学者,想知道如何在 UIWebView 中完成页面加载时显示图像,比如当你进入一个新网站时,图像开始出现在网络视图中的屏幕
您可以在网站加载的同时使用任何加载器,例如 MBProgressHUD
或任何其他进度条。
如果您愿意在加载时在屏幕上显示自定义图像,则可以在以下委托方法中处理:
假设您拍摄了任何名为 loadingView
的自定义图像或视图
func webView(webView: UIWebView!, didFailLoadWithError error: NSError!) {
**loadingView**.viewWithTag(1)?.hidden = true
print("Webview fail with error \(error)");
}
**func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {**
return true;
}
func webViewDidStartLoad(webView: UIWebView!) {
**loadingView**.viewWithTag(1)?.hidden = false
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView!) {
**loadingView**.viewWithTag(1)?.hidden = true
print("Webview did finish load")
}
希望对您有所帮助。
我是 swift 和 Xcode 的初学者,想知道如何在 UIWebView 中完成页面加载时显示图像,比如当你进入一个新网站时,图像开始出现在网络视图中的屏幕
您可以在网站加载的同时使用任何加载器,例如 MBProgressHUD
或任何其他进度条。
如果您愿意在加载时在屏幕上显示自定义图像,则可以在以下委托方法中处理:
假设您拍摄了任何名为 loadingView
的自定义图像或视图func webView(webView: UIWebView!, didFailLoadWithError error: NSError!) {
**loadingView**.viewWithTag(1)?.hidden = true
print("Webview fail with error \(error)");
}
**func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {**
return true;
}
func webViewDidStartLoad(webView: UIWebView!) {
**loadingView**.viewWithTag(1)?.hidden = false
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView!) {
**loadingView**.viewWithTag(1)?.hidden = true
print("Webview did finish load")
}
希望对您有所帮助。