The implementation method of UIWebView loading loading in IOS _ios

Source: Internet
Author: User

The first method: using UIView and Uiactivityindicatorview

Copy Code code as follows:

Create UIWebView
WebView = [[UIWebView alloc] Initwithframe:cgrectmake (0, 44, 320, 400)];
[WebView Setuserinteractionenabled:no];
[WebView Setbackgroundcolor:[uicolor Clearcolor]];
[WebView setdelegate:self];
[WebView setopaque:no];//makes web pages transparent
NSString *path = @ "http://www.baidu.com";
Nsurl *url = [Nsurl Urlwithstring:path];
[WebView Loadrequest:[nsurlrequest Requestwithurl:url]];
Create Uiactivityindicatorview Background Translucent 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];
Start Loading Data
-(void) Webviewdidstartload: (UIWebView *) WebView {
[Activityindicator startanimating];
}
Data load Complete
-(void) Webviewdidfinishload: (UIWebView *) WebView {
[Activityindicator stopanimating];
UIView *view = (UIView *) [Self.view viewwithtag:103];
[View Removefromsuperview];
}

The second method: using Uialertview and Uiactivityindicatorview

Copy Code code as follows:

Load a Web page animation
-(void) Webviewdidstartload: (UIWebView *) webview{
if (Myalert==nil) {
Myalert = [[Uialertview alloc] Initwithtitle:nil
Message: @ "read ..."
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];
}

Method Three: Use UIWebView to load GIF pictures, unless you want to use WebView, otherwise do not use this method to implement

Copy Code code as follows:

NSData *gif = [NSData datawithcontentsoffile: [[NSBundle Mainbundle] pathforresource:@ "1" oftype:@ "GIF"]];
View Build
UIWebView *webview = [[UIWebView alloc] initwithframe:cgrectmake (100, 100, 70, 30)];
webview.userinteractionenabled = no;//User is not interactive
[WebView loaddata:gif mimetype:@ "Image/gif" Textencodingname:nil Baseurl:nil];
[Self.view Addsubview:webview];

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.