【问题标题】:How Do I import a local HTML file to my Swift Playground Live View?如何将本地 HTML 文件导入到我的 Swift Playground Live View?
【发布时间】:2018-03-30 11:52:40
【问题描述】:

以下是将本地 html 文件导入 swift Playground 的代码。它不工作,但我在实时视图中得到一个空白图像:

import UIKit
import WebKit
import PlaygroundSupport
let u = URL(string: "Prac_1.html")
let request:URLRequest = URLRequest(url: u!) 
let webView=UIWebView(frame:CGRect(x:0,y:0,width:768.0,height:1024.0))
webView.loadRequest(request) //Loading the request
PlaygroundPage.current.liveView = webView

【问题讨论】:

    标签: swift3 swift-playground


    【解决方案1】:

    将 HTML 文件复制到 Playground 的“资源”文件夹(转到“导航器”>“显示项目导航器”以显示该文件夹)。

    然后使用Bundle.main.url(forResource:) 获取文件的URL,如下所示:

    let u = Bundle.main.url(forResource: "Prac_1", withExtension: "html")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多