Reputation: 7370
I have HTML code that I get from a web service - it has style tags,(CSS I think) images and that sort of thing. I want to display it in a web view and have the remote images load as well as all the styling.
I've tried to set it like this:
[self.webView setBackgroundColor:[UIColor clearColor]];
NSMutableString *myString = [NSMutableString stringWithString:self.itemDecription];
[myString replaceOccurrencesOfString:@">" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, [myString length])];
[myString replaceOccurrencesOfString:@"<" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, [myString length])];
[self.webView loadHTMLString:myString baseURL:nil];
However the web view just shows text without any styling and images don't load.
Upvotes: 0
Views: 351
Reputation: 263
Try this one:
NSString *myFile = [[NSBundle mainBundle] pathForResource:@"tag" ofType:@"html"];
NSString* myString = [NSString stringWithContentsOfFile:myFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:myString baseURL:nil];
Upvotes: 2