zoukankan      html  css  js  c++  java
  • UIWebView

     

    #import "ViewController.h"

     

    @interface ViewController ()<UIWebViewDelegate>

    @property (weak, nonatomic) IBOutlet UIWebView *webView;

    @property (weak, nonatomic) IBOutlet UIBarButtonItem *goBack;

    @property (weak, nonatomic) IBOutlet UIBarButtonItem *goForward;

     

    @end

     

    @implementation ViewController

     

    #pragma mark ----------------------

    #pragma mark Life Cycle

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        

        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

    //    NSURLRequest *request = [NSURLRequest requestWithURL:url];

        

        //加载网页

    //    [self.webView loadRequest:request];

        [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

        //设置代理

        self.webView.delegate = self;

    }

     

     

    -(void)test1

    {

        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

        //加载网页

        [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

    }

     

    -(void)test2

    {

        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

        //加载网页

        [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

        

        self.webView.scrollView.contentInset = UIEdgeInsetsMake(40, 0, 0, 0);

    }

     

    //加载本地的文件

    -(void)test3

    {

        NSURL *url = [NSURL fileURLWithPath:@"/Users/liuzhenjie/Desktop/桌面/69a83772jw1etbs1jc10yj2336224npd.jpg"];

        //加载网页

        [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

    }

     

    -(void)test4

    {

        NSURL *url = [NSURL URLWithString:@"http://www.autohome.com.cn/guangzhou/"];

        //加载网页

        [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

        

        //设置时候自适应

        self.webView.scalesPageToFit = YES;

    }

     

    -(void)test5

    {

        NSURL *url = [[NSBundle mainBundle] URLForResource:@"text.html" withExtension:nil];

        

        //加载网页

        [self.webView loadRequest:[NSURLRequest requestWithURL:url]];

        

        //设置时候自适应

        self.webView.dataDetectorTypes = UIDataDetectorTypeAll;

    }

    #pragma mark ----------------------

    #pragma mark Events

    - (IBAction)goBackBtnClick:(id)sender

    {

        

        [self.webView goBack];

    }

    - (IBAction)goForwardBtnClick:(id)sender

    {

        [self.webView goForward];

        

    }

    - (IBAction)reloadBtnClick:(id)sender

    {

        [self.webView reload];

    }

     

    #pragma mark ----------------------

    #pragma mark UIWebViewDelegate

     

    //即将加载某个请求的时候调用

    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

    {

        NSLog(@"%@",request.URL.absoluteString);

        //简单的请求拦截处理

        NSString *strM = request.URL.absoluteString;

        if ([strM containsString:@"360"]) {

            return NO;

        }

        return YES;

    }

     

    //1.开始加载网页的时候调用

    -(void)webViewDidStartLoad:(UIWebView *)webView

    {

        NSLog(@"webViewDidStartLoad");

    }

     

    //2.加载完成的时候调用

    -(void)webViewDidFinishLoad:(UIWebView *)webView

    {

        NSLog(@"webViewDidFinishLoad");

        

        self.goBack.enabled = self.webView.canGoBack;

        self.goForward.enabled = self.webView.canGoForward;

    }

     

    //3.加载失败的时候调用

    -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

    {

        NSLog(@"didFailLoadWithError");

    }

     

    @end

  • 相关阅读:
    当我们谈线(进)程“切换”时
    机器学习算法实现——线性回归
    从cpu加电到加载OS内核的详细过程(清华大学ucore-lab1总结一)
    X86 I/O端口
    【转】实模式和保护模式
    链接器(linker)的作用——CSAPP第7章读书笔记
    【转】Derivation of the Normal Equation for linear regression
    使用PowerShell创建Active Directory用户对象(域用户)
    使用Powershell安装WSFC
    临时自定义数学算符添加正下方下标
  • 原文地址:https://www.cnblogs.com/liuzhenjie/p/5480222.html
Copyright © 2011-2022 走看看