5

I have a form sheet segue that should display hard-coded html page. Now I have a two part problem first problem is

 <CENTER><H1>A Simple Sample Web Page</H1><H4>By Frodo</H4>
<H2>Demonstrating a few HTML features</H2></CENTER>

is displayed like

enter image description here

I can change <CENTER>tag to <left> in that case it works but it limits my options. How can I display this content In the middle of the screen without alignment issues?

Second part of the question is How can I embed a color or a link to content. On line ""FFFFFF">\n" I get the error that says Expected ':' and on line "<a href="http://somegreatsite.com">\n" Half of the line is green which is seems like comment on the screen that means it will not executed by XCode

My full code is like :

- (void) createWebViewWithHTML{
    //create the string
    NSMutableString *html = [NSMutableString stringWithString: @"<html><head><title></title></head><body style=\"background:transparent;\">"];

    //continue building the string
    [html appendString:@"<BODY BGCOLOR="
     ""FFFFFF">\n"
     "<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM">
     "</CENTER> \n"
     "<HR>\n"
     "<a href="http://somegreatsite.com">\n"
     "Link Name</a>\n"

     "is a link to another nifty site\n"

     "<H1>This is a Header</H1>\n"

     "<H2>This is a Medium Header</H2>\n"

     "Send me mail at <a href="mailto:[email protected]">\n"

     "[email protected]</a>.\n"

     "<P> This is a new paragraph!\n"

     "<P> <B>This is a new paragraph!</B>\n"

     "<BR> <B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>\n"

     "<HR>\n"];
    [html appendString:@"</body></html>"];

    //instantiate the web view
    webView = [[UIWebView alloc] initWithFrame:self.view.frame];


    //make the background transparent
    [webView setBackgroundColor:[UIColor clearColor]];

    //pass the string to the webview
    [webView loadHTMLString:[html description] baseURL:nil];

    //add it to the subview
    [self.view addSubview:webView];

} 

Edit:: Added story board picture

enter image description here

So how can I make correct alignment and embed color/link correctly?

3
  • 1
    try giving webView = [[UIWebView alloc] initWithFrame:self.view. bounds ]; instead of frame Commented Oct 8, 2012 at 15:10
  • Why [html description] instead of just html? Commented Oct 8, 2012 at 15:20
  • isnt that how you pass string to webview ? Commented Oct 8, 2012 at 15:44

1 Answer 1

3
  1. Check if your UIWebView has the right size. It seems to be bigger than the screen.

  2. Place a \ before any " in your hard-coded string. e.g.:

    NSString *testString="This is a \"Test\"";
    

    results in

    This is a "Test"

Hope this helps

Sign up to request clarification or add additional context in comments.

2 Comments

it seems size doesnt matter :), that is what she said ha:) I have changed it few times but it is not recognized by Xcode. Added picture on question
changing code to webView = [[UIWebView alloc] initWithFrame:self.webView.frame]; and adding \ worked for me thank you

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.