0

I have a header string, footer string and body of the HTML page. I need to programmatically include some text in the body and then I need to input all this data in a UIWebView to load the page. I need to input the final HTML string into a UIWebView controler, so that it will launch the page I designed. Could someone please share your ideas how can I achieve this?

Thanks!

3
  • Did you any code regarding that or not? Commented Feb 21, 2012 at 13:16
  • Hi, Thanks for the reply. No, i didn't find any tutorial how to go ahead on this. But, I am only seeing how to read js or html files from directory and execute that page. Commented Feb 21, 2012 at 13:19
  • [webView loadHTMLString:htmlString baseURL:nil]; Commented Feb 21, 2012 at 14:20

1 Answer 1

2

You mean something like:

NSString *html = [NSString stringWithFormat: @"<html><head><style>body{background-color:black}</style></head><body>the body goes here</body>"];    
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0,76.0,320.0,404.0)];
[myWebView loadHTMLString:html baseURL:nil];

If you, for example, have head stored in headString and body in bodyString you could combine them with:

[NSString stringWithFormat: @"<html>%@%@</html>", headString, bodyString];
Sign up to request clarification or add additional context in comments.

2 Comments

@rokjarc How would you include a http header (i.e. 'Accept-Language: en-US' or 'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ')?
@ConfusedDeer: hmm, head in my answer refers to the <head> tag. According to this answer you could set the headers in shouldStartLoadWithRequest:. I didn't try it though.

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.