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!

Costique
  • 23,712
  • 4
  • 76
  • 79
Getsy
  • 4,887
  • 16
  • 78
  • 139

1 Answers1

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];
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • 1
    @rokjarc How would you include a http header (i.e. 'Accept-Language: en-US' or 'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ')? – ConfusedDeer Aug 28 '15 at 19:23
  • @ConfusedDeer: hmm, `head` in my answer refers to the `` tag. According to [this answer](http://stackoverflow.com/a/24683201/653513) you could set the headers in `shouldStartLoadWithRequest:`. I didn't try it though. – Rok Jarc Aug 31 '15 at 08:27