How to embed a html file into Xcode
This is how you embed a html file into your Xcode project.
1) Add your html file to the project. In our example it is test.html. We put it in
the root directory so we don't have to worry about the path.
2) Add a Web View where you want the html to appear.
3) Drag the UIWebView to the h file and call it MyHTMLfile and make sure connection
is Outlet and then press connect. When you are done, the h file should look like this:
@interface ViewController : UIViewController {
IBOutlet UIWebView *MyHTMLfile;
}
4) Copy paste this code into to m file:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL * bundle = [[NSBundle mainBundle] bundleURL];
NSURL *myURL = [NSURL URLWithString:@"test.html" relativeToURL:bundle];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[MyHTMLfile loadRequest:myRequest];
}
That's it folks. Have fun!
|
|
|
|
|