How to display html content on UIWebView IOS
Check if your
UIWebView
has the right size. It seems to be bigger than the screen.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
Mord Fustang
Updated on June 04, 2022Comments
-
Mord Fustang almost 2 years
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
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 saysExpected ':'
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 XCodeMy 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
So how can I make correct alignment and embed color/link correctly?