#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的使用,简单浏览器的实现的更多相关文章

  1. 基于Gecko内核的简单浏览器实现

    分享一个基于Gecko内核的简单浏览器实现过程. 项目需要需要开发一个简单浏览器,由于被访问的网页中有大量Apng做的动画,使用IE内核的webbrowser不能播放,使用基于WebKit和Cefsh ...

  2. IOS开发-UI学习-UIWebView,简单浏览器的制作

    制作一个简单的浏览器,包含网址输入框,Search按钮,前进.回退按钮,UIWebView就这几个简单的控件. UITextField:用来输入网址: UIbuttom:实现前进,后退,搜索等功能: ...

  3. 爬虫技术 -- 进阶学习(八)模拟简单浏览器(附c#代码)

    由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...

  4. 爬虫技术(五)-- 模拟简单浏览器(附c#代码)

    由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...

  5. C# 网络编程之最简单浏览器实现

    最近学习C#网络编程的HTTP协议编程,HTTP即Hypertext Transfer Protocol的缩写,意为:超文本传输协议. 其中与HTTP相关的知识主要有六个类的知识,分别是 (1).Ht ...

  6. 在 .NET 中开发基于 Chrome 内核的浏览器-创建一个简单浏览器

    首先在 http://www.cftea.com/tools/downloads/Cef.zip 下载文件包. 一.将文件解压拖入到 Visual Studio 对应的 WinForm 项目中. 二. ...

  7. 001 - 使用鸿蒙WebView创建简单浏览器 step 1

    打开官网,找到WebView的文档(模拟器不支持) 鸿蒙webview的开发指南(原始链接,方便大家识别并点击):https://developer.harmonyos.com/cn/docs/doc ...

  8. python3使用pyqt5制作一个超简单浏览器

    我们使用的是QWebview模块,这里也主要是展示下QWebview的用法. 之前在网上找了半天的解析网页的内容,都不是很清楚. 这是核心代码: webview = Qwebview() webvie ...

  9. [flex] as3.0 实现基于air的简单浏览器

    <?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx= ...

随机推荐

  1. Java [leetcode 29]Divide Two Integers

    题目描述: Divide two integers without using multiplication, division and mod operator. If it is overflow ...

  2. MYSQL select时锁定记录问题

    在使用SQL时,大都会遇到这样的问题,你Update一条记录时,需要通过Select来检索出其值或条件,然后在通过这个值来执行修改操作. 但当以上操作放到多线程中并发处理时会出现问题:某线程selec ...

  3. MySQL查询执行过程

    MySQL查询执行路径 1. 客户端发送一条查询给服务器: 2. 服务器先会检查查询缓存,如果命中了缓存,则立即返回存储在缓存中的结果.否则进入下一阶段: 3. 服务器端进行SQL解析.预处理,再由优 ...

  4. POJ 1017 Packets

    题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹. 解法:6×6的直接放进去,5×5的空隙可以用1× ...

  5. 编程精粹:编写高质量的C语言代码———笔记一

    第一章 假想的编译程序 要记得对空语句进行处理,最好使用NULL使其明显可见 char * strcpy(char* pchTo, char* pchFrom) { char* pchStart = ...

  6. jquery 单行滚动、批量多行滚动、文字图片翻屏滚动效果代码

    jquery单行滚动.批量多行滚动.文字图片翻屏滚动效果代码,需要的朋友可以参考下. 以下代码,运行后,需要刷新下,才能加载jquery,要不然看不到效果.一.单行滚动效果 <!DOCTYPE ...

  7. linux常识

    一.linux常识 1.为什么学习linux及如何学习linux? 基于linux的操作系统是一种自由和开放源代码的类UNIX操作系统,其定义组件是linux内核,其稳定性.安全性.处理多并发已经得到 ...

  8. java web接收POST数据

    新建一个ServerForPOSTMethod的动态网站工程

  9. 4.3 Reduction代码(Heterogeneous Parallel Programming class lab)

    首先添加上Heterogeneous Parallel Programming class 中 lab: Reduction的代码: myReduction.c // MP Reduction // ...

  10. 【Spark学习】Apache Spark项目简介

    引言:本文直接翻译自Spark官方网站首页 Lightning-fast cluster computing 从Spark官方网站给出的标题可以看出:Spark——像闪电一样快的集群计算 Apache ...