HTML To String Use WKWebview Swift 4



This time i will try to make a combined webview with html,
which is needed is the webkit WKwebview and on the coding below using fullcode, follow this step below



import UIKit
import WebKit

class HtmlToViewController: UIViewController {
    @IBOutlet weak var lHTMLtext: UILabel!
    lazy var webView: WKWebView = {
        let web = WKWebView()
        web.backgroundColor = UIColor.white
        web.isUserInteractionEnabled = true
        web.scrollView.showsHorizontalScrollIndicator = false
        web.scrollView.showsVerticalScrollIndicator = false
        web.translatesAutoresizingMaskIntoConstraints = false
        return web
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
            let htmlIsi = "t showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then turned to look out the window at the dull weather. Drops of rain could be heard hitting the pane, which made him feel quite sad
        webViewSy()
        webView.loadHTMLString("<head><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'><meta name='theme-color' content='#000000'><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' /><meta name='theme-color' content='#5A9C14'><meta name='msapplication-navbutton-color' content='#5A9C14'><meta name='apple-mobile-web-app-status-bar-style' content='#5A9C14'><link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'><style>:root,* {font-family: 'Roboto', sans-serif;font-size: 14px;color: rgb(114, 114, 114);text-align: justify;-webkit-user-select: none;user-select: none;}</style></head><body>\(htmlIsi)</body>", baseURL: nil)
        
    }
    
    func webViewSy() {
        
        self.view.addSubview(self.webView)
        self.webView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
        self.webView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
        self.webView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
        self.webView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
    }




Comment Below





No comments: