I want to style a web page meant for the desktop so that it is presentable on a UIWebView on iPhone. I do not have access to the web server from which the pages originate. I
SWIFT 3
If you (like me) only use a html snippet (not a complete web page) you need to add your local css file in the header of the html snippet.
I therefore define a html header like this:
let htmlHeader = " \n \n \n \n \n"
and a footer like this:
let htmlFooter = " \n "
Then find the baseURL for the css like this:
let baseURLForCss = Bundle.main.url(forResource: "default", withExtension: "css")
And load the html snippet with your own css like this:
webView.loadHTMLString(String.init(format: "%@%@&@", htmlHeader, htmlSnippet, htmlFooter), baseURL: baseURLForCss)