UIWebview基本使用(原生加载框UIActivityIndicatorView)
2016-07-04 20:29
495 查看
UIWebview的基本使用,并且自带加载框
- (void)viewDidLoad
{
[super viewDidLoad];
//设置webView的代理
_webView.delegate = self;
_indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_indicator.center = self.view.center;
_indicator.hidesWhenStopped = YES;
[self.view addSubview:_indicator];
}
- (IBAction)gotoWebsite:(UIButton *)sender
{
//UIWebView 网页视图,能够加载一个网页
NSURL *url = [NSURL URLWithString:_textFIeld.text];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//loadRequest 加载一个请求
[_webView loadRequest:request];
[_textFIeld resignFirstResponder];
}
- (IBAction)openFIleClick:(UIButton *)sender
{
//webView除了加载网页,还可以浏览一些常用的类型文件(pdf,doc,jpg,txt)等
NSString *path = [[NSBundle mainBundle]pathForResource:@"YiChat" ofType:@"pdf"];
//生成一个本地文件的URL
NSURL *url = [[NSURL alloc]initFileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//loadRequest 加载一个请求
[_webView loadRequest:request];
[url release];
}
//webView 将要加载一个请求时调用,返回YES继续加载,返回NO停止加载
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"%@",request.URL);
return YES;
}
//加载已经开始时调用
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[_indicator startAnimating];
}
//加载完成时调用
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[_indicator stopAnimating];
}
//加载失败时调用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[_indicator stopAnimating];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//设置webView的代理
_webView.delegate = self;
_indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_indicator.center = self.view.center;
_indicator.hidesWhenStopped = YES;
[self.view addSubview:_indicator];
}
- (IBAction)gotoWebsite:(UIButton *)sender
{
//UIWebView 网页视图,能够加载一个网页
NSURL *url = [NSURL URLWithString:_textFIeld.text];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//loadRequest 加载一个请求
[_webView loadRequest:request];
[_textFIeld resignFirstResponder];
}
- (IBAction)openFIleClick:(UIButton *)sender
{
//webView除了加载网页,还可以浏览一些常用的类型文件(pdf,doc,jpg,txt)等
NSString *path = [[NSBundle mainBundle]pathForResource:@"YiChat" ofType:@"pdf"];
//生成一个本地文件的URL
NSURL *url = [[NSURL alloc]initFileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//loadRequest 加载一个请求
[_webView loadRequest:request];
[url release];
}
//webView 将要加载一个请求时调用,返回YES继续加载,返回NO停止加载
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"%@",request.URL);
return YES;
}
//加载已经开始时调用
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[_indicator startAnimating];
}
//加载完成时调用
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[_indicator stopAnimating];
}
//加载失败时调用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[_indicator stopAnimating];
}
相关文章推荐
- android sudio 打包资料汇总
- 2.1 nagios 安装
- iOS滑动返回的最简单实现
- Context的使用
- android app瘦身
- Hybrid App学习心得:cordova + ionic + angularjs
- 在Android Studio环境下进行OpenCV开发
- 对之前Android基础的一些整理(一)
- Android Studio 中配置Annotationes框架
- Android蓝牙串口通信遇到的问题
- label
- 感觉今天一天没做什么事情啊QAQ,学习了一下java的基本语法,编写了几个小程序,还是总结一下吧
- Android之Launcher分析和修改3——Launcher启动和初始化
- 本地搭建IPv6环境测试APP
- 通过new Scanner(System.in)创建一个Scanner,命令行输出
- 基于SimpleAdapter与BaseAdapter的不同ListView实现
- 二维数组静态初始化输出99乘法表
- iOS Storyboard约束详解(附gif图)
- 静态分析Android程序——smali文件解析
- android中xml tools属性详解