librelist archives

« back to archive

How to allow for HTML rendering in UIWebView?

How to allow for HTML rendering in UIWebView?

Isa Ranjha
2013-04-15 @ 23:25
I have a UIWebView in which I am showing a certain object from an array 
(in this case, an email message body). I am doing this with the following 

NSString *string = [messages objectAtIndex:count-row-1];
NSString *string2 = [string stringByReplacingOccurrencesOfString:@"\n" 

[self.webView loadHTMLString:string2 baseURL:[NSURL 
fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
The problem with this code, the current one I am using, is that when the 
message body has some rich text or a lot of HTML images, formatting, etc.,
it does not display the message properly.

When I say 'it does not display to the message properly', I mean that all 
the above formatting is ignored, and just plain text from the image is 
pulled and shown.

Here is how I am loading the message body into the messages array:

for (CTCoreMessage *msg in messageSet) {
                [messages addObject:[msg bodyPreferringPlainText:&isHTML]];
isHTML is a BOOL set to NO, I don't know if this might be a problem?

I have now tried setting the isHTML BOOL to YES, and well, it fixed half 
of the problem. Now, some (most) formatting is shown (CSS/images/rich 
text), but unfortunately in the middle of some messages, I get tags like 
this, in the middle of no where:

style="margin-bottom: 15px; width: 570px; text-align: left; margin-left: 
auto; margin-right: auto;" 
What am I doing wrong?