网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

[IOS]UIWebView请求网络页面或者加载本地资源页面

UIWebView是一个能够显示网页的IOS视图控件,我们可以用它来访问一个网站。下面是具体的实例:

创新互联是一家专注于成都网站建设、网站设计与策划设计,崇明网站建设哪家好?创新互联做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:崇明等地区。崇明做网站价格咨询:18982081108

操作步骤:

1.首先在xib文件中拖放一个UIWebView控件到view中

2.将下载的页面以及页面资源加载到项目中,但必须选择Create folder references for any added folders,然后知道文件在项目中是蓝色显示,而不是×××显示

3.将webView的Delegate拖到File's Owner,继承UIWebView的Delegate协议,并且实现他的协议

[IOS]UIWebView 请求网络页面或者加载本地资源页面

ViewController.h:

#import   @interface DXWViewController : UIViewController @property (retain, nonatomic) IBOutlet UIWebView *webview; @property(nonatomic,retain) UIAlertView *alert; @end

ViewController.m:

#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请求网络页面或者加载本地资源页面
文章来源:http://bjjierui.cn/article/gsiese.html

其他资讯