Share on Google+Share on Google+

Embedding HTML in iPhone App

Advertisement
This example illustrate you how to embed the HTML in iPhone application. To embed the HTML file we required a UIWebView that will load the page in our application.

Embedding HTML in iPhone App

This example illustrate you how to embed the HTML in iPhone application. To embed the HTML file we required a UIWebView that will load the page in our application.

Once you create your application with UIWebView, create your ".html" file and add it under Resources folder. And just copy the given code into your view controller implementation file.

Syntax to embed HTML into UIWebView iphone app

- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"corejava" ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];

NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];

webView.opaque = NO;
webView.backgroundColor = [UIColor purpleColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];

}

The application will look like ...

If you do not want the color background in the UIWebView then do the needfull...
1. Set the UIWebView background property as clearColor
2. In HTML file <body style="background-color: transparent"> and
3. Set the opaque = NO

Download Code

Advertisements

Posted on: August 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.