首页 技术 正文
技术 2022年11月15日
0 收藏 634 点赞 2,524 浏览 1457 个字

UIWebView 是苹果提供的用来展示网页的UI控件,它也是最占内存的控件。

iOS8.0之后出现了webkit框架,WKWebView相比UIWebView节省了1/4~1/3的内存,速度快,但是没缓存功能。

对于一些购物类app网页的展示是必不可免的,因此UIWebView对于我们来说也是必须精通的控件。

下面给大家先简单展示一下UIWebView。

 //
// ViewController.m
// UIWebView
// #import "ViewController.h" @interface ViewController ()<UIWebViewDelegate> @property (nonatomic, strong) UIWebView * webView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
//初始化webView
_webView = [[UIWebView alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width, CGRectGetHeight(self.view.frame) - )]; NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"]; [_webView loadRequest:[NSURLRequest requestWithURL:url]];
//把webView添加到View上
[self.view addSubview:_webView]; }
/*
- (void)reload; 刷新
- (void)stopLoading; 停止load - (void)goBack; 返回
- (void)goForward; 前进
*/
@end

UIWebView

运行结果

网络天荒地老之UIWebView&WebKit

接下来我们来一个Webkit的demo

网络天荒地老之UIWebView&WebKit

 //
// ViewController.m
// 句子迷
//
// Created by ma c on 16/4/7.
// Copyright © 2016年 晓宁. All rights reserved.
// #import "ViewController.h"
#import <WebKit/WebKit.h>
@interface ViewController ()
@property(nonatomic,strong)WKWebView*webView;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
self.webView=[[WKWebView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.juzimi.com"]]];
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

WebKit

展示结果如下

网络天荒地老之UIWebView&WebKit

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,117
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927