gpt4 book ai didi

ios - WkWebView 不会加载 HTMLstring

转载 作者:IT王子 更新时间:2023-10-29 05:40:35 28 4
gpt4 key购买 nike

我试图在 WkWebView 中显示我之前下载并存储在字符串中的 html 页面。

这就是我设置 WkWebView 的方式:

    webView = WKWebView(frame: self.blankView.frame)
webView.navigationDelegate = self
webView.loadHTMLString(tipShow.htmlString!, baseURL: nil)
view.addSubview(webView)

我要显示的 html 字符串是:

      <html> <style type="text/css"> * { -webkit-touch-callout: none; -webkit-user-select: none; /*
Disable selection/copy in UIWebView */
}
</style> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,
initial-scale=1">

<title>TITLE</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script
src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> </head>

<body>




<div data-role="page" id="page1">

<div align=justify style="margin-left:20px; margin-right:20px">

<font size="4.5" face="HelveticaNeue-Light"><br>

<p>
THIS IS A TEST
</p>
</div> </div>

</body></html>

当 WkWebView 显示在我的 View 中时,它永远保持这样。

enter image description here

有人可以向我解释为什么以及如何解决这个问题吗?

最佳答案

SWIFT

你可能把它弄得太复杂了。这对我有用......

首先导入WebKit

其次,在你的类下创建一个@IBOutlet:

@IBOutlet weak var webView: WKWebView!

第三,将以下内容放入您的 viewDidLoad() 中:

let htmlString:String! = "\(YourString)"
webView.loadHTMLString(htmlString, baseURL: NSBundle.mainBundle().bundleURL)

SWIFT 3 更新

webView.loadHTMLString(htmlString, baseURL: Bundle.main.bundleURL)

关于ios - WkWebView 不会加载 HTMLstring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013812/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com