1

First of all let me point that I am just the beginner and that I might be missing something out, but I really need help figuring out how to get things done.

I've been able to parse xml from web address using https://github.com/tadija/AEXML parser.

Next, on WKWebView I'm using .loadHTMLString method to take only the content node of xml:

 webView.loadHTMLString(xml.root["channel"]["item"]["content"].string, baseURL: nil)

Now, my webView shows the content, but I need to format the style. I've been searching for hours now and the closest answer I could find is that i should use .css file, which makes sense and I already have custom style css file, but I can not manage to implement it. As far as I could conclude from similar questions either: in .loadHTMLString method I should use that custom css file in baseURL (if that is the case I would appreciate if someone could explain how to do it); or the answer lies in WKUserContentController with which i'm quite unfamiliar.

I would greatly appreciate any help.

Thanks a lot.

Karthik Kumar
  • 1,375
  • 1
  • 12
  • 29
IvanMih
  • 1,815
  • 1
  • 11
  • 23

1 Answers1

0

You need to link the css file into your html. If you have an external css (which I believe you have:-)) file add

<link rel="stylesheet" type="text/css" href="mystyle.css">

Alternatively you could implement an inline or internal css

JFYI

Somewhere in the head tag add Internal css:

<style>
body {
background-color: linen;
}

h1 {
color: maroon;
margin-left: 40px;
} 
</style>

Inline css:

<h1 style="color:blue;margin-left:30px;">This is a heading.</h1>

Hope it helps you! Happy coding :)

George_v
  • 83
  • 7
  • Hey @George_v thank you for your answer. I do have a file mystyle.css which i imported in my xcode project. If i understand correctly i should add a string: to my html string from xml feed? It should be simple string concatenation? – IvanMih Jan 16 '17 at 15:27
  • you should add it inside the html file, can you share the code of it ? – George_v Jan 16 '17 at 15:46
  • In the end i managed to solve the problem by adding to the html like @George_v said, but with one more step: baseURL in .loadHTMLString method have to be set to Bundle.main.resourceURL – IvanMih Jan 17 '17 at 15:02