I am using a WKWebview to display HTML. I would like to style the HTML using a locally hosted CSS file. I have tried many of the proposed solutions from the following posts, but have not been able to make them work for me.
- Insert CSS into loaded HTML in UIWebView / WKWebView
- WKWebView fails to load images and CSS using loadHTMLString(_, baseURL:)
- iOS WKWebview loadHTMLString(_ baseURL:) fails to load images and read css
While I am able to manually hardcode <link rel=\"stylesheet\" type=\"text/css\" href=\"markup.css\">
into the HTML and apply the CSS styles, I would love to know how to do this programmatically using JS or some other technique.
I created a sample project to help illustrate the issue. I have commented out the hardcoded line that works, but am hoping someone can shed light onto why this proposed solution isn't working for me. Open to other suggestions as well. Thanks in advance!