Embedding HTML in iPhone App


 

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.

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

Ads