0

I am trying to download a online page and override css with my custom css. However I couldn't have success.

I did the following steps:

  1. Download Html string from an online page
  2. Added "<link rel="stylesheet" type="text/css" href="styles.css">" to the page Html head. This styles.css contains a custom font and anothers css rules.
  3. Loaded this new Html string to WKWebView with webView.loadHTMLString(html, baseURL: Bundle.main.bundleURL)

Another option would be just download the page and override the css with a style tag between the head tag, however I need to add a custom @font-face from a font in my project resources.

Any ideas how can I accomplish this? If I set Bundle.main.bundleURL as my baseURL resources from the online page don't download. If I set nil as my baseURL I can't access my custom font...

1 Answer 1

1

I think you should use bundlePath instead of bundleURL like this.

let url = URL(fileURLWithPath: Bundle.main.bundlePath)
webView.loadHTMLString(html, baseURL: url)
Sign up to request clarification or add additional context in comments.

1 Comment

I have social feeds embeded to my web content and I lose them if I change baseURL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.