zoukankan      html  css  js  c++  java
  • iOS WKWebView简单实现

    代码实现如下
    #import “ViewController.h”
    #import <WebKit/WebKit.h>
    @interface ViewController ()
    @property (nonatomic,strong)WKWebView * webView;
    @end
    
    @implementation ViewController
    
    (void)viewDidLoad {
    [super viewDidLoad];
    
    _webView = [[WKWebView alloc] initWithFrame:self.view.bounds];//初始化
    
    
    [self.view addSubview:_webView];


    //1.网络
    _webView.allowsBackForwardNavigationGestures = YES;
     NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]; 

    [_webView loadRequest:request];



    //2.本地html 
     //获取bundlePath 路径
        NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
        
        //获取本地html目录 basePath
        NSString *basePath = [NSString stringWithFormat: @"%@/dist", bundlePath];
        
        //获取本地html目录 baseUrl
        NSURL *baseUrl = [NSURL fileURLWithPath: basePath isDirectory: YES];
        
        NSLog(@"%@", baseUrl);
        //html 路径
        
        NSString *indexPath = [NSString stringWithFormat: @"%@/index.html", basePath];
        //html 文件中内容
        NSString *indexContent = [NSString stringWithContentsOfFile: indexPath encoding: NSUTF8StringEncoding error:nil];
        //显示内容
        [webview loadHTMLString: indexContent baseURL: baseUrl];
    
    }
  • 相关阅读:
    加密文件夹 | 彻底隐藏文件夹
    Swing的概述
    Java SE练习题——求奇数
    多线程有什么用?
    Robot的使用
    基础的Servlet
    Angular Resolver 学习
    GoLang 学习
    Angular Material 控件学习
    Angular 学习小记
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/13048575.html
Copyright © 2011-2022 走看看