IOS中UIWebView加載Loading的實(shí)現(xiàn)方法
第一種方法:使用UIView and UIActivityIndicatorView
//創(chuàng)建UIWebView
WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];
[WebView setUserInteractionEnabled:NO];
[WebView setBackgroundColor:[UIColor clearColor]];
[WebView setDelegate:self];
[WebView setOpaque:NO];//使網(wǎng)頁透明
NSString *path = @" NSURL *url = [NSURL URLWithString:path];
[WebView loadRequest:[NSURLRequest requestWithURL:url]];
//創(chuàng)建UIActivityIndicatorView背底半透明View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setTag:103];
[view setBackgroundColor:[UIColor blackColor]];
[view setAlpha:0.8];
[self.view addSubview:view];
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[activityIndicator setCenter:view.center];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:activityIndicator];
[self.view addSubview:WebView];
[view release];
[WebView release];
//開始加載數(shù)據(jù)
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activityIndicator startAnimating];
}
//數(shù)據(jù)加載完
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
UIView *view = (UIView *)[self.view viewWithTag:103];
[view removeFromSuperview];
}
第二種方法:使用UIAlertView and UIActivityIndicatorView
//加載網(wǎng)頁動(dòng)畫
- (void)webViewDidStartLoad:(UIWebView *)webView{
if (myAlert==nil){
myAlert = [[UIAlertView alloc] initWithTitle:nil
message: @"讀取中..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(120.f, 48.0f, 38.0f, 38.0f);
[myAlert addSubview:activityView];
[activityView startAnimating];
[myAlert show];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[myAlert dismissWithClickedButtonIndex:0 animated:YES];
}
方法三:使用UIWebView來加載gif圖片,除非你要用到webView,不然就不要使用這種方式來實(shí)現(xiàn)
NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"]];
// view生成
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(100, 100, 70, 30)];
webView.userInteractionEnabled = NO;//用戶不可交互
[webView loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
[self.view addSubview:webView];
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
相關(guān)文章
iOS 動(dòng)畫 —— 禮花效果實(shí)例詳細(xì)
這篇文章主要介紹了iOS 動(dòng)畫 —— 禮花效果實(shí)例詳細(xì)的相關(guān)資料,需要的朋友可以參考下2016-09-09關(guān)于iOS GangSDK的使用 為App快速集成社群公會(huì)模塊
這篇文章主要介紹了iOS GangSDK的使用為App快速集成社群公會(huì)模塊功能的實(shí)現(xiàn)過程。2017-11-11在IOS系統(tǒng)上滾動(dòng)條滾動(dòng)到指定的位置出現(xiàn)空白頁面的解決方案
這篇文章主要介紹了 在IOS系統(tǒng)上滾動(dòng)條滾動(dòng)到指定的位置出現(xiàn)空白頁面的解決方案,需要的朋友可以參考下2017-01-01Xcode 10升級(jí)導(dǎo)致項(xiàng)目報(bào)錯(cuò)的常見問題解決
這篇文章主要給大家介紹了關(guān)于Xcode 10升級(jí)導(dǎo)致項(xiàng)目報(bào)錯(cuò)的常見問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12IOS中用正則表達(dá)式判斷輸入的內(nèi)容為8-16位且同時(shí)包含數(shù)字和字母
這篇文章主要介紹了IOS中用正則表達(dá)式判斷輸入的內(nèi)容為8-16位且同時(shí)包含數(shù)字和字母,需要的朋友可以參考下2017-06-06