#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. C# 向共享文件夹上传及下载文件

    //第一步建立共享链接 public static bool connectState(string path, string userName, string passWord) { bool Fl ...

  2. 如何在asp.net mvc3中使用HttpStatusCode

    下载了asp.net mvc 4的源码看了看,没怎么看清楚.不过个人觉得MVC4 beta中Web API这个是比较不错的,虽然说它是往传统回归. web api最好的莫过于它更加适合使用jquery ...

  3. AM335x(TQ335x)学习笔记——挂载Ramdisk

    上篇文章中我们已经能够通过u-boot启动内核了,但是没有能够启动成功,从内核的log中可以看出,内核启动失败的原因是没有挂载到root文件系统,本文将使用busybox制作根文件系统并打包成ramd ...

  4. (转载)memcpy的几个实现版本

    (转载)http://blog.sina.com.cn/s/blog_4d3a41f40100cvza.html 实现void *memcpy(void *to, const void *from, ...

  5. volatile之一--volatile不能保证原子性

    Java语言是支持多线程的,为了解决线程并发的问题,在语言内部引入了 同步块 和 volatile 关键字机制在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这 ...

  6. Jquery+asp.net后台数据传到前台js进行解析的方法

    所以在解析后台数据的时候,我们需要根据后台的数据情况,特殊处理和对待. 我这里后台用的是asp.net提供的wcf服务,也有ashx一般处理程序.大致原理差不多. C#中我们经常用的对象,有实体对象比 ...

  7. 谈谈Nginx有哪些特点

    1.热部署        我个人觉得这个很不错.在master管理进程与worker工作进程的分离设计,使的Nginx具有热部署的功能,那么在7×24小时不间断服务的前提下,升级Nginx的可执行文件 ...

  8. HW7.8

    import java.util.ArrayList; import java.util.Scanner; public class Solution { public static void mai ...

  9. -lrt

    在编写pthread有关的程序时,编译时老是报"undefined reference to `pthread_create'"的错误,原因是没有链接pthread相关的库,gcc ...

  10. C 头文件阅读理解

    __BEGIN_DECLS ..... ..... __END_DECLS 很多时候,为了使 C 代码和 C++ 代码保持互相兼容的过程调用接口,需要在 C++ 代码里加上 extern " ...