如何在 webview (swift 4.0) 中设置 html 字符串

Pin*_*put 7 html swift xcode9

当我尝试加载这种类型的html字符串时,我遇到了问题

(<p>Identify the arrow-marked structures in the images<img alt=\"\" src=\"https:\/\/dams-apps-production.s3.ap-south-1.amazonaws.com\/course_file_meta\/73857742.PNG\" \/><\/p>\r\n)
Run Code Online (Sandbox Code Playgroud)

webview。问题是由于向后倾斜而引发的。

任何帮助都会受到赞赏

Kru*_*nal 6

URL 字符串/在您的 html 字符串中存在正斜杠问题。

在此处输入图片说明

正确的 url 字符串是:https : //dams-apps-production.s3.ap-south-1.amazonaws.com/course_file_meta/73857742.PNG

在这里,我尝试了这个及其工作:

class WebKitController: UIViewController {

    @IBOutlet weak var webView: WKWebView!

    override func viewDidLoad() {
       super.viewDidLoad()
       loadHTMLStringImage()
    }

    func loadHTMLStringImage() -> Void {
        let htmlString = "<p>Identify the arrow-marked structures in the images<img alt=\"\" src=\"https://dams-apps-production.s3.ap-south-1.amazonaws.com/course_file_meta/73857742.PNG\"></p>"
        webView.loadHTMLString(htmlString, baseURL: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

结果:

在此处输入图片说明


And*_*jen 1

如果反斜杠是您的问题,您应该将其删除:

let origString = ...
let unescapedString = origString.replacingOccurrences(of: "\\", with: "")
webview.loadHTMLString(unescapedString, baseURL:nil)
Run Code Online (Sandbox Code Playgroud)