我有一个本地 HTML文件,我想在UIWebView中加载,但也想在里面传递一个参数.我可以加载HTML文件 webView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!)) 我想将
webView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!))
我想将本地传递给HTNL,如apprules.html?lang = ja.有没有办法在Swift中这样做?
Swift 3及以上:let url1 = Bundle.main.url(forResource: "apprules", withExtension: "html")! let url2 = URL(string: "?lang=ja", relativeTo: url1)! webView.loadRequest(NSURLRequest(url: url2))
斯威夫特2及以下:
let url1 = NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")! let url2 = NSURL(string: "?lang=ja", relativeToURL: url1)! webView.loadRequest(NSURLRequest(URL: url2))