对UIWebView的学习
建工程,建一个类WebViewController 继承于UIViewController
#import "WebViewController.h" @interface WebViewController ()
{
UIWebView *_webView;
UITextField *_textField;
UIActivityIndicatorView *_activityIndicatorView;
}
@end @implementation WebViewController
-(void)dealloc
{
[_webView release];
[_textField release];
[_activityIndicatorView release];
[super dealloc];
}
//webView获取url地址
- (void)loadWebPageWithString:(NSString *)urlstring
{
NSURL *url = [NSURL URLWithString:urlstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
//点击按钮,网页加载
- (void)buttonPress:(id)sender
{
[_textField resignFirstResponder];
[self loadWebPageWithString:_textField.text];
}
//代理中的方法
-(void)webViewDidStartLoad:(UIWebView *)webView
{
//网页加载时 进度轮开始启动
[_activityIndicatorView startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//网页加载完成 进度轮停止
[_activityIndicatorView stopAnimating];
}
//请求页面出现错误:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网址输入错误或网络断开" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
[alertView release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
_textField = [[UITextField alloc] initWithFrame:CGRectMake(, , , )];
_textField.borderStyle = UITextBorderStyleRoundedRect;
//输入框默认显示http://www.baidu.com
_textField.text = @"http://www.baidu.com";
//点击button进入网页
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(, , , );
[button setTitle:@"GO" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
//网页显示
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(, , , )];
_webView.delegate = self;
[self.view addSubview:_webView];
[self.view addSubview:_textField];
[self.view addSubview:button];
//设置进度轮
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(, , , )];
//进度轮中心位置
[_activityIndicatorView setCenter:self.view.center];
//进度轮显示类型
[_activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[self.view addSubview:_activityIndicatorView];
//没有点击按钮时,执行方法进入默认显示网页
[self buttonPress:nil]; // Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
实例代码:LiSWebView.zip
对UIWebView的学习的更多相关文章
- ios网络学习------4 UIWebView的加载本地数据的三种方式
ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...
- 关于学习是UIWebView的一些思考
前几天因为数据中加载有html语言的数据,关于html语言和UIWebView,有一些纠结,经过几天的研究,也有了一些自己的简单的见解. 我有两个页面需要加载html语言(注意,这里 ...
- (转)UIWebView全部API学习
网上找的收藏一下 http://www.myexception.cn/web/1888974.html 最生僻的API做了下划线以及粗体的标注.百度上查了全是拷贝的同一份代码,而且只有代码没有解释,很 ...
- 一步一步学习Swift之(四)玩转UIWebView
实现原理: 1.通过UIWebView的stringByEvaluatingJavaScriptFromString方法来触发脚本 2.通过自定义连接来触发oc代码 实现过程 @IBOutlet we ...
- ios学习网络------4 UIWebView以三种方式中的本地数据
UIWebView这是IOS内置的浏览器.能够浏览网页,打开文档 html/htm pdf docx txt等待格文档类型. safari浏览器是通过UIWebView制作. server将 ...
- IOS开发-UI学习-UIWebView,简单浏览器的制作
制作一个简单的浏览器,包含网址输入框,Search按钮,前进.回退按钮,UIWebView就这几个简单的控件. UITextField:用来输入网址: UIbuttom:实现前进,后退,搜索等功能: ...
- ios学习之UIWebView网页视图调整
//先来一个可行的小Demo程序:结合searchBar的google搜索 #import <UIKit/UIKit.h> @interface ViewController : UIVi ...
- ios学习之UIWebView网页视图
转载于爱德凡的百度空间,地址:http://hi.baidu.com/aidfan/item/34a720866b33cbcdef083d37 UIWebView 使用详解 一.UIWebView加载 ...
- Swift学习之熟悉控件
最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...
随机推荐
- ubuntu 软件安装的几种方法
说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行方式进行的软件包安装.卸载和删除的方法. 一.U ...
- bzoj 2245: [SDOI2011]工作安排
#include<cstdio> #include<iostream> #include<cstring> #define M 10000 #define inf ...
- 【HDU2087】KMP
KMP算法其实很好理解,就是在匹配串中找最近的相同的串. 下面是HDU的2087: #include<iostream> #include<cstdio> #include&l ...
- javaweb之Cookie篇
Cookie是在浏览器访问某个Web资源时,由Web服务器在Http响应消息头中通过Set-Cookie字段发送给浏览器的一组数据. 一个Cookie只能表示一个信息对,这个信息对有一个信息名(Nam ...
- matlab代码 图像处理源码
非常不错的找图像处理源码的地方,源码搜搜. http://www.codesoso.com/Category.aspx?CategoryId=56
- 机器翻译(noip2010)
分析:该题是经典的队列题目,直接用队列实现就可以.如果数据范围大一些的话还可hash判重! 这可以说是一道送分的题目,但是还有粗心的学生会在这里失分,主要原因是数组的范围定义的不合适,因为空间足够用, ...
- CPU MPU MCU SOC SOPC关系及区别
在嵌入式开过程,会经常接触到一些缩写术语概念,这些概念在嵌入式行业中使用率非常高,下面我们就解释一下这些概念之间的关系和区别: 1.CPU(Central Processing Unit),是一台计算 ...
- python3 nonlocal vs global
考虑这样一个python程序: x = 12 def func(): x = 1 func() print(x) 输出为:x = 12 因为函数内部定义的x被认为只属于局部作用域,为了表明我么引用的是 ...
- 技术解析:锁屏绕过,三星Galaxy系列手机也能“被”呼出电话
近期,由两位安全研究人员,Roberto Paleari及Aristide Fattori,发布了关于三星Galaxy手机设备安全漏洞的技术细节.据称,Galaxy手机可在锁屏状态下被未授权的第三方人 ...
- php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动
php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动 每个人机器不一样,我手头是个air book,查了一下现在最好在mac下,用mamp, mamp百科介绍 , ...