zoukankan      html  css  js  c++  java
  • uiwebview 加载本地js、css、img,html从网站加载

    资源文件都是放在根目录下

    1、index.html

    <html>
    <head>
    <title>My test Page</title>
    <link rel="stylesheet" href = "test.css" type="text/css"/>
    <script type = "text/javascript" src = "22.js"></script>
    </head>
    <body>
    <h1 id="food" onclick ="sayHello()">Click me!</h1>
    <img src="114.png" width="128" height="128" />
    </body>
    </html>

    2、22.js

    function sayHello() {

        if (document.getElementById('foo').innerHTML == 'Hi there'){

            document.getElementById('foo').innerHTML = 'Click me!';

            

        }else{

            document.getElementById('foo').innerHTML = 'Hi there'

        }

    }

     3、test.css

    body{

        color:red;

        background-color:#fff;

        font-size:12px;

        font-style:italic;

        font-weight:bold;

        font-family:Arial;

    }

    4、oc 代码 

        webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        [self.view addSubview:iWebView];

        [webView setBackgroundColor:[UIColor whiteColor]];

         NSString *path = [[NSBundle mainBundle] bundlePath];

        NSURL *baseURL = [NSURL fileURLWithPath:path];

        NSString *imageStr=[NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.155/index.html"] encoding:NSUTF8StringEncoding error:nil];

          [webView loadHTMLString:imageStr baseURL:baseURL];

    5、原理就是先把服务端的html拉下来,然后通过webview加载本地html的方式加载,

  • 相关阅读:
    NET CORE EF事务
    搭建Vue-nuxt.js
    VUE获取URL(导航)参数方法
    第十二届蓝桥杯大赛软件赛决赛题解
    第十二届蓝桥杯大赛软件赛省赛第二场题解
    P1955 [NOI2015] 程序自动分析
    P1621 集合
    将博客搬至CSDN
    2021第六届GPLT 团体程序设计天梯赛CCCC 个人题解
    Divide by Zero 2021 and Codeforces Round #714 (Div. 2)
  • 原文地址:https://www.cnblogs.com/sgdkg/p/5576906.html
Copyright © 2011-2022 走看看