当前位置: 移动技术网 > IT编程>移动开发>IOS > IOS中UIWebView加载Loading的实现方法

IOS中UIWebView加载Loading的实现方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

背着你歌词,夏娃的诱惑2,赵志刚离婚

第一种方法:使用uiview and uiactivityindicatorview

复制代码 代码如下:

//创建uiwebview
webview = [[uiwebview alloc] initwithframe:cgrectmake(0, 44, 320, 400)];
[webview setuserinteractionenabled:no];
[webview setbackgroundcolor:[uicolor clearcolor]];
[webview setdelegate:self];
[webview setopaque:no];//使网页透明
nsstring *path = @"";
nsurl *url = [nsurl urlwithstring:path];
[webview loadrequest:[nsurlrequest requestwithurl:url]];
//创建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];
//开始加载数据
- (void)webviewdidstartload:(uiwebview *)webview {  
      [activityindicator startanimating];       
}
//数据加载完
- (void)webviewdidfinishload:(uiwebview *)webview {
     [activityindicator stopanimating];  
     uiview *view = (uiview *)[self.view viewwithtag:103];
     [view removefromsuperview];
}

第二种方法:使用uialertview and uiactivityindicatorview

复制代码 代码如下:

//加载网页动画
- (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,不然就不要使用这种方式来实现

复制代码 代码如下:

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]; 

以上所述就是本文的全部内容了,希望大家能够喜欢。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网