IOS开发-UI学习-UIWebView,简单浏览器的制作
制作一个简单的浏览器,包含网址输入框,Search按钮,前进、回退按钮,UIWebView就这几个简单的控件。
UITextField:用来输入网址;
UIbuttom:实现前进,后退,搜索等功能;
UIWebView:实现网页展示。
准备工作:
右键Info.plist并Open As Source Code,打开之后添加以下代码段:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
以上代码段功能:有些网址为Http,要搞成Https,具体原理以后探索出来了再补充。
言归正传,实现浏览器功能的具体代码如下:
#import "ViewController.h"
@interface ViewController (){
// 定义全局变量,各个控件
UIWebView *mywebview;
UIButton *backbutton;
UIButton *goforbutton;
UITextField *urlField;
UIButton *searchButton;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 添加浏览器view,
mywebview = [[UIWebView alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width, self.view.frame.size.height-)];
[self.view addSubview:mywebview];
// 网址输入框
urlField = [[UITextField alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width-, )];
urlField.borderStyle = UITextBorderStyleRoundedRect;
urlField.text= mywebview.request.URL.absoluteString;
[self.view addSubview:urlField];
// search button
searchButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-, , , )];
searchButton.backgroundColor = [UIColor redColor];
[searchButton setTitle:@"Search" forState:UIControlStateNormal];
[searchButton addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:searchButton];
// 返回按键
backbutton = [[UIButton alloc]initWithFrame:CGRectMake(, self.view.frame.size.height-, , )];
backbutton.backgroundColor = [UIColor redColor];
[backbutton setTitle:@"返回" forState:UIControlStateNormal];
[backbutton addTarget:self action:@selector(backFbution:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backbutton];
// 前进按钮
goforbutton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-, self.view.frame.size.height-, , )];
goforbutton.backgroundColor = [UIColor redColor];
[goforbutton setTitle:@"前进" forState:UIControlStateNormal];
[goforbutton addTarget:self action:@selector(goFobution:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:goforbutton];
}
//返回按钮绑定事件
-(void)backFbution:(id)sender{
[mywebview goBack];
}
//前进按钮绑定事件
-(void)goFobution:(id)sender{
[mywebview goForward];
}
//搜索按钮绑定事件
-(void)search:(id)sender{
[mywebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlField.text]]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
运行效果如下(请无视UI所用颜色。。。。。):

存在一个问题,就是我在百度里面随便点击一个网址链接之后,可以打开网址,但打开之后浏览器的网址输入框中的网址依然是之前那个,没有改变为当前网站地址。这个问题遗留下来。。。
IOS开发-UI学习-UIWebView,简单浏览器的制作的更多相关文章
- iOS开发UI篇—UITabBarController简单介绍
iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...
- iOS开发UI篇—Modal简单介绍
iOS开发UI篇—Modal简单介绍 一.简单介绍 除了push之外,还有另外一种控制器的切换方式,那就是Modal 任何控制器都能通过Modal的形式展⽰出来 Modal的默认效果:新控制器从屏幕的 ...
- iOS开发UI篇—Kvc简单介绍
ios开发UI篇—Kvc简单介绍 一.KVC简单介绍 KVC key valued coding 键值编码 KVC通过键值间接编码 补充: 与KVC相对的时KVO,即key valued observ ...
- iOS开发UI篇—UIWindow简单介绍
iOS开发UI篇—UIWindow简单介绍 一.简单介绍 UIWindow是一种特殊的UIView,通常在一个app中只会有一个UIWindow iOS程序启动完毕后,创建的第一个视图控件就是UIWi ...
- iOS开发UI篇—Quartz2D简单介绍
iOS开发UI篇—Quartz2D简单介绍 一.什么是Quartz2D Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\ ...
- iOS开发UI篇—Quartz2D简单使用(一)
iOS开发UI篇—Quartz2D简单使用(一) 一.画直线 代码: // // YYlineview.m // 03-画直线 // // Created by apple on 14-6-9. // ...
- iOS开发UI篇—Quartz2D简单使用(二)
iOS开发UI篇—Quartz2D简单使用(二) 一.画文字 代码: // // YYtextview.m // 04-写文字 // // Created by 孔医己 on 14-6-10. // ...
- iOS开发UI篇—Quartz2D简单使用(三)
iOS开发UI篇—Quartz2D简单使用(三) 一.通过slider控制圆的缩放 1.实现过程 新建一个项目,新建一个继承自UIview的类,并和storyboard中自定义的view进行关联. 界 ...
- iOS开发UI篇—popoverController简单介绍
iOS开发UI篇—popoverController简单介绍 一.简单介绍 1.什么是UIPopoverController 是iPad开发中常见的一种控制器(在iPhone上不允许使用) 跟其他控制 ...
- iOS开发UI篇—Quartz2D简单使用(一)
iOS开发UI篇—Quartz2D简单使用(一) 一.画直线 代码: 1 // 2 // YYlineview.m 3 // 03-画直线 4 // 5 // Created by apple on ...
随机推荐
- 转:LR性能测试结果样例分析 测试结果分析
LoadRunner性能测试结果分析是个复杂的过程,通常可以从结果摘要.并发数.平均事务响应时间.每秒点击数.业务成功率.系统资源.网页细分图.Web服务器资源.数据库服务器资源等几个方面分析,如图1 ...
- The Importance of Money in Life
What were you taught about money as you were growing up?something like "Money doesn't grow on t ...
- SecureCRT 上传文件的两种方法 Zmodem、SFTP
Zmodem: 无论有xshell还是secureCRT连接linux的时. 默认都用一个zmodem可以帮助window和linux之间传输文件 很方便和实用的工具. 不过默认是无法使用的 需要安装 ...
- tps,qps
http://blog.itpub.net/22664653/viewspace-767265/
- Android ART运行时无缝替换Dalvik虚拟机的过程分析
Android ART运行时无缝替换Dalvik虚拟机的过程分析 分类: Android2014-01-13 00:59 42722人阅读 评论(66) 收藏 举报 AndroidARTDalvikV ...
- 通过ant调用shell脚本执行adb命令
在Hudson或者Jenkins中利用ant的exec 来调用shell命令,通过shell脚本来执行adb shell命令,可以正常执行,不会出现在ant中直接调用adb shell出现的假死情况. ...
- Git 学习资源
在线教程 Try Git: Git初学者绝不能错过的Git上手资源. 廖雪峰Git教程: 比较系统的中文在线教程 易百Git教程 : 另一个比较全的中文在线教程 Git Immersion : A V ...
- java中创建多线程的方式
在java中比较常用的有三种创建多线程的方式. 方式一:继承Thread类,要重写run方法. 在MyThread类 public class MyThread extends Thread { @O ...
- Django之路: 模版篇
一.Django 模版 上章是介绍简单的把django.http.HttpResponse的内容显示到网页上,下面就介绍以下如何使用渲染模版的方法来显示内容.本节代码是基于Django 1.8,但 ...
- MC34063中文资料及应用实例(转)
源:http://blog.chinaunix.net/uid-26199686-id-3207838.html MC34063A(MC33063)芯片器件简介 该器件本身包含了DC/DC变换器所需要 ...