iOS about the use of UIWebView controls

Source: Internet
Author: User


@interface Xiaochedingweiviewcontroller () <UIWebViewDelegate>
{
Jgprogresshud *hud;
UIView *_hudview;
UIWebView *webview;
NSString *ipstring;
NSString *string;
}
@end

@implementation Xiaochedingweiviewcontroller

-(void) Viewdidload {
[Super Viewdidload];
Blue Strip
UILabel *label=[[uilabel alloc]initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, 50)];
Label.backgroundcolor=[uicolor colorwithred:46/255.0 green:104/255.0 blue:182/255.0 alpha:1.0];
[Self.view Addsubview:label];
UILabel *label0 = [[UILabel alloc]initwithframe:cgrectmake (SELF.VIEW.FRAME.SIZE.WIDTH/2-50, 10, 100, 40)];
Label0.text = @ "school bus positioning";
Label0.textcolor = [Uicolor Whitecolor];
Label0.textalignment = Nstextalignmentcenter;
Label0.backgroundcolor = [Uicolor Clearcolor];
[Self.view addsubview:label0];
Self.view.backgroundColor = [Uicolor Whitecolor];
Exit
UIButton *backbutton = [UIButton buttonwithtype:uibuttontypecustom];
Backbutton.frame =cgrectmake (10, 10, 100, 40);
[Backbutton addtarget:self Action: @selector (Gotoback) forcontrolevents:uicontroleventtouchupinside];
[Backbutton settitle:@] < return to "Forstate:uicontrolstatenormal";
Backbutton.contenthorizontalalignment = Uicontrolcontenthorizontalalignmentleft;
[Self.view Addsubview:backbutton];
Clear the cache, the usual UIWebView default is the cache function.
[[Nsurlcache Sharedurlcache] removeallcachedresponses];

if (WebView = = nil) {
Webview=[[uiwebview alloc]initwithframe:cgrectmake (0, Self.view.frame.size.width, SELF.VIEW.FRAME.SIZE.HEIGHT-50)];
}
Webview.backgroundcolor=[uicolor Whitecolor];
Webview.scalespagetofit=yes;
Webview.delegate = self;
[Self getip];
if ([ipstring isequaltostring:@ "192.168.33"]) {

string = @ "Http://192.168.33.203:8090/3dschool/car.htm";
}else
{
http://www.q-map.com.cn:8280
string = @ "Http://kl.scst.edu.cn:8280/3dschool/car.htm";
string = @ "Http://www.q-map.com.cn:8280/3dschool/car.htm";
string = @ "Http://192.168.33.203:8090/3dschool/car.htm";
}
[WebView loadrequest:[nsurlrequest Requestwithurl:[nsurl urlwithstring:string]];
[(Uiscrollview *) [[WebView subviews] objectatindex:0] setbounces:no];
[Self.view Addsubview:webview];
[Self showhudview];
HUD = [[Jgprogresshud Alloc]initwithstyle:jgprogresshudstyledark];
Hud.textLabel.text = @ "Loading ...";

}

#pragma mark-Gets the current network IP address
-(void) getip{
NSString *string = [NSString deviceipadress];
if ([String isequaltostring:@ "An error occurred when obtaining IP address"]) {



}else
{
Nsarray *iparray = [String componentsseparatedbystring:@ ".];
ipstring = [NSString stringwithformat:@ "%@.%@.%@", iparray[0],iparray[1],iparray[2]];
}
}

-(void) Showhudview
{
_hudview = [[UIView alloc]initwithframe:cgrectmake (0, Self.view.frame.size.width, self.view.frame.size.height-50 )];
_hudview.backgroundcolor = [Uicolor Whitecolor];
[Self.view Addsubview:_hudview];
}

This function is called when WebView starts loading, and we show here Coverview
-(void) Webviewdidstartload: (UIWebView *) WebView
{
[HUD Showinview:_hudview Animated:yes];
}

This function is called when the WebView is loaded and we remove the coverview here
-(void) Webviewdidfinishload: (UIWebView *) WebView
{
[Self removehudview];
}

-(void) Removehudview
{

[HUD Dismissanimated:yes];
if (_hudview) {
[UIView animatewithduration:0.5 animations:^{
_hudview.alpha = 0;
} completion:^ (BOOL finished) {
_hudview = nil;
}];
}

}


-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (Nullable Nserror *) error
{
NSLog (@ "%@", error);
[Self removehudview];
NSString *str = [NSString stringwithformat:@ "%@", Error.localizeddescription]
Mbprogresshud *_hud = [Mbprogresshud showHUDAddedTo:self.navigationController.view animated:yes];

Set the annular determinate mode to show task progress.
_hud.mode = Mbprogresshudmodetext;
_hud.label.text = nslocalizedstring (str, @ "HUD Message title");
Move to Bottm Center.

_hud.backgroundview.style = Mbprogresshudbackgroundstylesolidcolor;

_hud.offset = Cgpointmake (0.f, Mbprogressmaxoffset);

[_hud Hideanimated:yes afterdelay:1.0];


}

-(void) gotoback{
[Self.navigationcontroller Popviewcontrolleranimated:yes];
}

-(void) didreceivememorywarning {
[Super didreceivememorywarning];

}

iOS about the use of UIWebView controls

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.