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

时间: 2024-08-24 15:24:59

UIWebView的使用,简单浏览器的实现的相关文章

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

制作一个简单的浏览器,包含网址输入框,Search按钮,前进.回退按钮,UIWebView就这几个简单的控件. UITextField:用来输入网址: UIbuttom:实现前进,后退,搜索等功能: UIWebView:实现网页展示. 准备工作: 右键Info.plist并Open As       Source Code,打开之后添加以下代码段: 1 <key>NSAppTransportSecurity</key> 2 <dict> 3 <key>NSA

Android之WebView的使用与简单浏览器

在要浏览网页的时候,第一种我们可以通过Intent来使用自带的浏览器,第二种可以通过WebView这个控件来浏览. 第一种很简单,直接看代码: Uri uri = Uri.parse("http://www.baidu.com/"); Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri); startActivity(launchBrowser); 第二种就稍微复杂点 首先我们要对WebView这个控件有一个XML布局:

UIWebView --- 内置的浏览器控件 加载网页

描述:UIWebVIew 是IOS一个常见的控件,属内置的浏览器控件,可以用来加载网页,或是打开文件等等. 方法一: 代码实现:(运行程序时,直接显示链接的内容) #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSURL * url=[NSURL URLWithSt

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

首先在 http://www.cftea.com/tools/downloads/Cef.zip 下载文件包. 一.将文件解压拖入到 Visual Studio 对应的 WinForm 项目中. 二.在解决方案中,在这些文件上右键,选择属性,在“复制到输出目录”中选择“始终复制”(不要忘了 locales 中的文件也要这样操作). 三.项目上右键添加引用:CefSharp.dll.CefSharp.WinForms.dll 四.在 WinForm 相应的位置使用类似如下的代码: [csharp]

MFC控件Microsoft Web Browser简单浏览器实现

环境:VS2013 新建工程:基于对话框 ①在对话框添加控件Microsoft Web Browser(说明:VS2013上控件的名字是Microsoft Web Browser,其它的编译器额就不知道了) ②头函数: #include <afxinet.h> //for WinInet ②对所添加的控件设置环境变量(在此我把环境变量设置为m_sa) ③在OnInitDialog()里设定你想要打开的网页 m_sa.Navigate("http://www.baidu.com&quo

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

<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width=&

iOS网络篇3-利用UIWebView做一个浏览器功能

在UIkit中,苹果封装了一个特别好用的控件UIWebView能够实现简单的网页加载和文件加载 一.加载网页资源 1.首先新建一个singleView项目,在storyboard拖如下控件 2.设置相关属性连接如下 3.在ViewController.m里的类扩展遵守UISearchBarDelegate和UIWebViewDelegate @interface ViewController () <UISearchBarDelegate,UIWebViewDelegate> /**网页展示*

UIWebView 操作

网络开发中,当公司已经使用 HTML5 技术实现同时适应 Android 和 iOS 等多个平台的网页时,这时往往需要我们 iOS 平台能够嵌入网页并进行各种交互,那我们应该怎么做来实现这种需求呢? 这里我们考虑的方案就是:使用 UIWebView 网页控件 本随笔简单介绍如何使用 UIWebView 网页控件: (1)简单浏览器 file://WhatsNewIniPhoneOS.pdf 读取本地资源文件 http://www.apple.com 读取网站内容 KenmuHuang 读取百度搜

创建浏览器的基本

#import "ViewController.h" @interface ViewController ()<UIScrollViewDelegate> //保包括这个viewdelegat协议 @property (weak, nonatomic) IBOutlet UITextField *search; //这是输入框 @property (weak, nonatomic) IBOutlet UIWebView *viewbrows; // 这个是浏览器界面视图 @