UIWebView是一个能够显示网页的IOS视图控件,我们可以用它来访问一个网站。下面是具体的实例:
创新互联是一家专注于成都网站建设、网站设计与策划设计,崇明网站建设哪家好?创新互联做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:崇明等地区。崇明做网站价格咨询:18982081108
操作步骤:
#import <UIKit/UIKit.h> @interface DXWViewController : UIViewController<UIWebViewDelegate> @property (retain, nonatomic) IBOutlet UIWebView *webview; @property(nonatomic,retain) UIAlertView *alert; @end
#import "DXWViewController.h" @interface DXWViewController () @end @implementation DXWViewController - (void)viewDidLoad { [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; //[self.webview loadRequest:request]; //加载本地资源,html页面 NSString *str = [[NSBundle mainBundle] pathForResource:@"百度图片—全球最大中文图片库" ofType:@"html"]; str = [NSString stringWithContentsOfFile:str encoding:NSUTF8StringEncoding error:nil]; NSLog(@"%@",str); [self.webview loadHTMLString:str baseURL:[[NSBundle mainBundle] bundleURL]]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [_webview release]; [_alert release]; [super dealloc]; } -(void)webViewDidFinishLoad:(UIWebView *)webView { [self.alert dismissWithClickedButtonIndex:0 animated:YES]; } -(void)webViewDidStartLoad:(UIWebView *)webView { self.alert = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; [self.alert show]; UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; aiv.center = CGPointMake(self.alert.bounds.size.width/2, self.alert.bounds.size.height/2); [aiv startAnimating]; [self.alert addSubview:aiv]; } @end
当前名称:[IOS]UIWebView请求网络页面或者加载本地资源页面
文章源于:https://www.cdcxhl.com/article34/gsiese.html
成都网站建设公司_创新互联,为您提供定制网站、品牌网站制作、网站策划、建站公司、、App设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联