Loading string in UIWebview

后端 未结 4 2159
清歌不尽
清歌不尽 2021-02-07 04:04

How to load a string like below in UIWebview

\"\\n
\\nEgestas rhoncus auctor ac. Risus parturient, mid ultrices nisi.\\U00a0
\\nAugue ac elementum duis aliquet d         


        
相关标签:
4条回答
  • 2021-02-07 04:09

    Here is the Code

     NSString* htmlString= @"hereyourSTring";
     [webView loadHTMLString:htmlString baseURL:nil];
    

    this would load the String in WEBview.

    0 讨论(0)
  • 2021-02-07 04:15

    This is pretty simple As Below,

     [self.webView loadHTMLString:htmlString baseURL:nil];
    

    You can specify the baseURL to get relative paths working. Is this what you were looking for ? Or more general explanations about UIWebView ?

    0 讨论(0)
  • 2021-02-07 04:15

    In Swift 3

    let webView = UIWebView()
    webView.loadHTMLString("htmlString", baseURL: nil)
    

    But note, that you won't preserve line breaks. To preserve line breaks you'll need to replace \n with <\br> as done by @MANIAK_dobrii in above answer

    0 讨论(0)
  • 2021-02-07 04:26

    You should use:

    [webView loadHTMLString:string baseURL:nil];
    

    But note, that you won't preserve line breaks. To preserve line breaks you'll need to replace \n with <\br> (or any valid line breaking html), so this turns into:

    [webView loadHTMLString:[string stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"] baseURL:nil];
    
    0 讨论(0)
提交回复
热议问题