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

操作步骤:

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

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

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


ViewController.h:

#import <UIKit/UIKit.h>

@interface DXWViewController : UIViewController<UIWebViewDelegate>
@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

最新文章

  1. Java web.xml 配置详解
  2. 深入理解 Javascript 面向对象编程
  3. 一个NULL引发的血案
  4. tomcat deploy部署项目三种方法
  5. PHP慕课网教程
  6. 51nod 1120 机器人走方格 V3 卡特兰数 lucas定理
  7. 鸟哥笔记:postfix的一些重要配置文件
  8. 【原创】MapReduce编程系列之二元排序
  9. Linux一
  10. C# 模拟POST提交文件
  11. C程序设计语言练习题1-13
  12. 百度静态资源(JS)公共库
  13. json格式数据,将数据库中查询的结果转换为json, 然后调用接口的方式返回json(方式一)
  14. 转 ogg组件介绍
  15. MLDS笔记:Generalization
  16. Python 遇到的坑
  17. 7.封装,static,方法重载
  18. ruby学习-字符串
  19. python环境和工具
  20. Spark Structured Stream 2

热门文章

  1. JavaScript 输入验证器工具
  2. hdu 2079 选课时间_母函数
  3. 一起来学canvas (前言)
  4. 【转】Android LCD(二):LCD常用接口原理篇
  5. openssl 生成CSR
  6. 所闻所获5:关于iOS的证书
  7. lua 类实现
  8. 使用 React 和 Flux 创建一个记事本应用
  9. NFS(网络文件系统的搭建)
  10. javax inect