[英]Add a custom background image as my uiwebview starts to load (using Swift)
Technologies: XCode6, iOS 8.2, Swift 技术: XCode6,iOS 8.2,Swift
My web view takes a few seconds to fully load and I wanted to add a background image while users were waiting. 我的网页视图需要几秒钟才能完全加载,我想在用户等待时添加背景图像。 I can easily change the color of the background, but what is the best way to add a background image?
我可以轻松更改背景的颜色,但添加背景图像的最佳方法是什么?
override func viewDidLoad() {
super.viewDidLoad()
webView.delegate = self
self.navigationController?.toolbarHidden = false;
openLoadingPopup()
webView.backgroundColor = UIColor.blackColor();
if browserHistory.count < 1 {
backButton.enabled = false
}
}
func webViewDidFinishLoad(webView: UIWebView) {
UIApplication.sharedApplication()
. networkActivityIndicatorVisible = false
closeLoadingPopup()
if cacheURL {
++browserHistoryIndex
browserHistory.insert(webView.request!.URL, atIndex:
browserHistoryIndex)
backButton.enabled = browserHistoryIndex != 0
}
}
I would suggest using a UIImageView
that covers the UIWebView
while it is loading. 我建议在加载时使用覆盖
UIWebView
的UIImageView
。 Once the webViewDidFinishLoad
is called, you can hide the image view. 调用
webViewDidFinishLoad
,您可以隐藏图像视图。
To make it less jarring, you could quickly fade the image view in and out. 为了减少震动,您可以快速淡入和淡出图像视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.