zoukankan      html  css  js  c++  java
  • 网络天荒地老之UIWebView&WebKit

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

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

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

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

     1 //
     2 //  ViewController.m
     3 //  UIWebView
     4 //
     5 
     6 
     7 #import "ViewController.h"
     8 
     9 @interface ViewController ()<UIWebViewDelegate>
    10 
    11 @property (nonatomic, strong) UIWebView * webView;
    12 
    13 @end
    14 
    15 @implementation ViewController
    16 
    17 - (void)viewDidLoad {
    18     [super viewDidLoad];
    19     //初始化webView
    20     _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, CGRectGetHeight(self.view.frame) - 60)];
    21 
    22     NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];
    23     
    24     [_webView loadRequest:[NSURLRequest requestWithURL:url]];
    25     //把webView添加到View上
    26     [self.view addSubview:_webView];
    27 
    28 }
    29 /*
    30  - (void)reload;  刷新
    31  - (void)stopLoading; 停止load
    32  
    33  - (void)goBack; 返回
    34  - (void)goForward; 前进
    35  */
    36 @end
    UIWebView

    运行结果

    接下来我们来一个Webkit的demo

     1 //
     2 //  ViewController.m
     3 //  句子迷
     4 //
     5 //  Created by ma c on 16/4/7.
     6 //  Copyright © 2016年 晓宁. All rights reserved.
     7 //
     8 
     9 #import "ViewController.h"
    10 #import <WebKit/WebKit.h>
    11 @interface ViewController ()
    12 @property(nonatomic,strong)WKWebView*webView;
    13 @end
    14 
    15 @implementation ViewController
    16 
    17 - (void)viewDidLoad {
    18     [super viewDidLoad];
    19     self.webView=[[WKWebView alloc]initWithFrame:self.view.bounds];
    20     [self.view addSubview:self.webView];
    21     [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.juzimi.com"]]];
    22     // Do any additional setup after loading the view, typically from a nib.
    23 }
    24 
    25 - (void)didReceiveMemoryWarning {
    26     [super didReceiveMemoryWarning];
    27     // Dispose of any resources that can be recreated.
    28 }
    29 
    30 @end
    WebKit

    展示结果如下

     

  • 相关阅读:
    【转】QT中添加的资源文件qrc时的路径问题小结
    【转】Qt 资源图片删除后,错误 needed by `debug/qrc_image.cpp'. Stop. 的终极解决办法
    普通类型与自定义类型之间的转化
    快速实现python c扩展模块
    关于解决python线上问题的几种有效技术
    OpenGL超级宝典笔记----渲染管线
    读python源码--对象模型
    python与c互相调用
    OpenGL超级宝典笔记----框架搭建
    python笔记(持续更新)
  • 原文地址:https://www.cnblogs.com/iOSlearner/p/5381456.html
Copyright © 2011-2022 走看看