0

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:@"&lt;" 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.

1
  • Can you show a sample of the 'HTML' Commented May 14, 2014 at 13:15

1 Answer 1

2

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];
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but how do I load my NSString into those strings?
i can't get you properly .

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.