#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. 对于requirejs AMD模块加载的理解

    个人人为使用模块化加载的优点有三: 1,以我的项目为例:90%为图表展示,使用的是echarts,此文件较大,requirejs可以在同一个版本号(urlArgs)之下缓存文件,那么我就可以在访问登陆 ...

  2. Dapper连接Oracle

    Dapper连接Oracle去年写过了篇博客,名字叫:让dapper支持Oracle 网址:http://www.cnblogs.com/ushou/archive/2012/09/28/270690 ...

  3. Java [leetcode 25]Reverse Nodes in k-Group

    题目描述: Given a linked list, reverse the nodes of a linked list k at a time and return its modified li ...

  4. C# 等待另外一个窗体关闭,再进行主线程的代码

    方法1 用Form类或其子类的showDialog方法. 比如你在form1里有一个按扭,然后你在Form1的点击事件里写上显示form2的代码: Form2 frm=new Form2(); frm ...

  5. “菜单”(menubar)和“工具栏”(toolbars)

    "菜单"(menubar)和"工具栏"(toolbars) "菜单" (menubar)和"工具栏"(toolbars) ...

  6. Samung Galaxy III I535 黑砖救活经过

    昨天不小心把手机给搞成黑砖了,如下是昨天发帖求助,结果还没审核过,晕. http://bbs.zhiyoo.com/forum.php?mod=viewthread&tid=9673138&a ...

  7. codeforce--600D - Area of Two Circles' Intersection

    题意:求相交圆的面积.借鉴大神代码,精度超高. #include <fstream> #include <iostream> #include <string> # ...

  8. C#编程中的66个好习惯,你有多少个?(转)

    http://www.cnblogs.com/jxsoft/archive/2012/01/11/2318824.html

  9. 在生成 Visual c + + 2005年或从 DLL 文件中使用 CString 派生的类的 Visual c + +.net 应用程序时,您可能会收到 LNK2019 错误消息

    http://support.microsoft.com/kb/309801

  10. Nullable问题

    在代码中经常遇到int? 其实int?是Nullable<int>的简写方式. int到int?转化 int? i=null; int j=0; i=j; int?到int转化 ; int ...