UIWebView的使用,简单浏览器的实现
#import "ViewController.h"
@interface ViewController () <UIWebViewDelegate>
@property(nonatomic,weak)UIWebView* web;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self _setTextField];
[self _loadWebView];
}
#pragma mark - 设置输入框
- (void)_setTextField{
self.tf.clearButtonMode=UITextFieldViewModeWhileEditing;
}
#pragma mark - 载入WebView
- (void)_loadWebView{
UIWebView* web=[[UIWebView alloc] init];
web.frame=CGRectMake(0,self.view.frame.size.height,self.view.frame.size.width,self.view.frame.size.height-42 );
self.web=web;
web.delegate=self;
[self.view addSubview:web];
}
#pragma mark - 放弃第一响应
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.tf resignFirstResponder];
}
#pragma mark - Action
- (IBAction)backAction:(id)sender {
[self.web goBack];
// self.web.frame=CGRectMake(0,self.view.frame.size.height,self.view.frame.size.width,self.view.frame.size.height-42 );
}
- (IBAction)forwardAction:(id)sender {
[self.web goForward];
self.web.frame=CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-50);
}
- (IBAction)undoAction:(id)sender {
[self.web stopLoading];
}
- (IBAction)refreshAction:(id)sender {
[self.web reload];
}
- (IBAction)searchAction:(id)sender {
[self.tf resignFirstResponder];
self.web.frame=CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-60);
[self _sendRequest];
}
#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
// NSLog(@"%d===%d",[webView canGoBack],[webView canGoForward]);
self.backBt.enabled=[webView canGoBack];
self.forwardBt.enabled=[webView canGoForward];
self.refresh.enabled=([webView canGoBack] ||[webView canGoForward]);
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(@"%@",error);
}
- (void)_sendRequest{
//http://www.baidu.com
NSURL* url=[NSURL URLWithString:self.tf.text];
NSURLRequest* request=[NSURLRequest requestWithURL:url];
[self.web loadRequest:request];
}
@end
UIWebView的使用,简单浏览器的实现的更多相关文章
- 基于Gecko内核的简单浏览器实现
分享一个基于Gecko内核的简单浏览器实现过程. 项目需要需要开发一个简单浏览器,由于被访问的网页中有大量Apng做的动画,使用IE内核的webbrowser不能播放,使用基于WebKit和Cefsh ...
- IOS开发-UI学习-UIWebView,简单浏览器的制作
制作一个简单的浏览器,包含网址输入框,Search按钮,前进.回退按钮,UIWebView就这几个简单的控件. UITextField:用来输入网址: UIbuttom:实现前进,后退,搜索等功能: ...
- 爬虫技术 -- 进阶学习(八)模拟简单浏览器(附c#代码)
由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...
- 爬虫技术(五)-- 模拟简单浏览器(附c#代码)
由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...
- C# 网络编程之最简单浏览器实现
最近学习C#网络编程的HTTP协议编程,HTTP即Hypertext Transfer Protocol的缩写,意为:超文本传输协议. 其中与HTTP相关的知识主要有六个类的知识,分别是 (1).Ht ...
- 在 .NET 中开发基于 Chrome 内核的浏览器-创建一个简单浏览器
首先在 http://www.cftea.com/tools/downloads/Cef.zip 下载文件包. 一.将文件解压拖入到 Visual Studio 对应的 WinForm 项目中. 二. ...
- 001 - 使用鸿蒙WebView创建简单浏览器 step 1
打开官网,找到WebView的文档(模拟器不支持) 鸿蒙webview的开发指南(原始链接,方便大家识别并点击):https://developer.harmonyos.com/cn/docs/doc ...
- python3使用pyqt5制作一个超简单浏览器
我们使用的是QWebview模块,这里也主要是展示下QWebview的用法. 之前在网上找了半天的解析网页的内容,都不是很清楚. 这是核心代码: webview = Qwebview() webvie ...
- [flex] as3.0 实现基于air的简单浏览器
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx= ...
随机推荐
- Android handler Thread 修改UI Demo
/********************************************************************** * Android handler Thread 修改U ...
- 移动端web页面使用position:fixed问题
在做移动端项目时,碰到一个很纠结的问题,头部固定的问题,一开始使用fixed,发现一系列的问题, 问题1:footer输入框 focus 状态,footer 被居中,而不是吸附在软键盘上部. 测试环境 ...
- 【Grunt】
GRUNT The JavaScript Task Runnerhttp://gruntjs.com/ Grunt打造前端自动化工作流http://tgideas.qq.com/webplat/inf ...
- Java 程序员在写 SQL 时常犯的 10 个错误
Java程序员编程时需要混合面向对象思维和一般命令式编程的方法,能否完美的将两者结合起来完全得依靠编程人员的水准: 技能(任何人都能容易学会命令式编程) 模式(有些人用“模式-模式”,举个例子,模式可 ...
- Java [leetcode 21]Merge Two Sorted Lists
题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by spli ...
- Month Calendar
http://www.codeproject.com/Articles/10840/Another-Month-Calendar#xx4614180xx Another Month Calendar ...
- NGINX开篇
前言 最近空闲时间比较多, 开始阅读nginx源码, 阅读的过程总结和笔记整理了下, 汇集成了一个系列的文章, 由于nginx功能实在太多, 没法做到面面俱到, 只对已经阅读过的源码进行记录总结, 以 ...
- 卸载sql server 2012
好不容易装上了sql server 2012数据库,可是却不能连接本地的数据库,后来发现缺少一些服务,于是决定重新安装,但是卸载却很麻烦,如果卸载不干净的话,重新安装会出问题,所以下面就总结一些方法: ...
- 使用linq 对 DataTable 中的数据进行 查询 与 分类求合
A:linq 的查询方式写得可以非常简洁如下所示: DataTable dt = null; private void XtraForm1_Load(object sender, Eve ...
- 第一个App“今日材料报价”上架,记录一下【原】
App Store地址:https://itunes.apple.com/us/app/jin-ri-cai-liao-bao-jia/id967274552?l=zh&ls=1&mt ...