iOS WebView
2015-10-09 21:25
92 查看
具体代码:(需要使用到第三方等待视图-MBProgressHUD,自己导入)
#import "ViewController.h"
#import "MBProgressHUD.h"
@interface ViewController ()<UIWebViewDelegate>
{
MBProgressHUD *HUD;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//
网页视图
UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];
[self.view addSubview:webView];
/*
//这是加载本地文件的
// - (void)loadRequest:(NSURLRequest *)request
加载本地文件
或者网页
NSString *path = [[NSBundle mainBundle]pathForResource:@"123pdf" ofType:@"pdf"];
NSURLRequest *resquest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
// 如果是网页视图
需要一个加载的请求 加载的内容
放在请求里面
*/
//
加载网页的
NSURLRequest *resquest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"https://www.baidu.com"]];
// *****
注意要有https://
webView.delegate = self;
[webView loadRequest:resquest];
//
等待视图
HUD = [[MBProgressHUD alloc]initWithView:self.view];
[self.view addSubview:HUD];
}
#pragma mark-WebView的代理方法
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[HUD show:YES];
HUD.labelText = @"正在拼命加载";
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[HUD hide:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"%@",error);
HUD.labelText = [NSString stringWithFormat:@"错误:无网络"];
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import "ViewController.h"
#import "MBProgressHUD.h"
@interface ViewController ()<UIWebViewDelegate>
{
MBProgressHUD *HUD;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//
网页视图
UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];
[self.view addSubview:webView];
/*
//这是加载本地文件的
// - (void)loadRequest:(NSURLRequest *)request
加载本地文件
或者网页
NSString *path = [[NSBundle mainBundle]pathForResource:@"123pdf" ofType:@"pdf"];
NSURLRequest *resquest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
// 如果是网页视图
需要一个加载的请求 加载的内容
放在请求里面
*/
//
加载网页的
NSURLRequest *resquest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"https://www.baidu.com"]];
// *****
注意要有https://
webView.delegate = self;
[webView loadRequest:resquest];
//
等待视图
HUD = [[MBProgressHUD alloc]initWithView:self.view];
[self.view addSubview:HUD];
}
#pragma mark-WebView的代理方法
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[HUD show:YES];
HUD.labelText = @"正在拼命加载";
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[HUD hide:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"%@",error);
HUD.labelText = [NSString stringWithFormat:@"错误:无网络"];
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- 看一手的有字幕的Google Android开发视频
- Android读书笔记-------View事件体系(2)滑动及弹性滑动
- iOS开源项目学习——开源中国iOS客户端
- Android Studio基本设置
- 【iOS】多线程GCD
- Android 数据传递方式
- Android数据库简单操作之创建数据库
- [Android] 定时器的实现(一)
- iOS 本地通知
- iOS CollectionView
- Unity3d渲染层级关系小结
- Android调用系统相机拍照保存照片很小解决方案
- Android基础入门教程——8.1.1 Android中的13种Drawable小结 Part 1
- Android真正简单的教程-第十二枪(ViewFlipper实现滑动效果)
- LeetCode(202) Happy Number
- iOS开发-进阶:代码块 block
- LeetCode(202) Happy Number
- iOS 动力效果
- Android获取组件的进程名
- Android 布局技巧