uiwebview html 位置,使用uiwebview中的本地html从相对路径加载资源

这段代码展示了如何在Swift中使用NSBundle加载名为'dados'的HTML文件,并将其路径转换为NSURL来创建NSURLRequest,最后在WebView中加载这个请求。该文件位于项目的根目录下,扩展名为'html'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

d7d35733fa60278832c2dd9069f7a569.png

jeck猫

在Swift中: func pathForResource(  name: String?, 

                        ofType ext: String?, 

                        inDirectory subpath: String?) -> String?  {

  // **name:** Name of Hmtl

  // **ofType ext:** extension for type of file. In this case "html"

  // **inDirectory subpath:** the folder where are the file. 

  //    In this case the file is in root folder

    let path = NSBundle.mainBundle().pathForResource(             "dados",

                                                     ofType:      "html", 

                                                     inDirectory: "root")

    var requestURL = NSURL(string:path!)

    var request = NSURLRequest(URL:requestURL)

    webView.loadRequest(request)}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值