How to Load large HTML string in WebView with LoadHTMLString method?

前端 未结 2 1887
忘掉有多难
忘掉有多难 2021-01-24 06:41

I have to load an html string onto the UIWebView with \'LoadHTMLString\' method of UIWebView.

Please find the below code.

[wv loadHTMLString:[NSString st         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-24 07:03

    After two days, long sleep, I've come up with this.

    Swift

    let path = NSBundle.mainBundle().pathForResource("public_html/index", ofType: "html")
    var html = try? NSString(contentsOfFile: path! as String, encoding: NSUTF8StringEncoding)
    html = html?.stringByReplacingOccurrencesOfString("#latitude#", withString:"

    Center aligned text.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

    ") webView.loadHTMLString(html as! String, baseURL: NSURL(fileReferenceLiteral: "public_html"))

    First, my HTML code is in my project ( public_html/index.html ). This code loads the HTML, converts it, replaces the tag '#latitude#' and loads the HTML using the directory ( for loading JS, etc.).

提交回复
热议问题