views:

31

answers:

1

Could I ship my app with an html document and display this using a UIWebView? How hard is this to use?

Is it possible to have a small frame with the UIWebView inside, or does it always take up the whole screen? And can I get rid of all those controls, so the UIWebView works like an advanced UILabel or UITextView?

+2  A: 

Yes; it's easy; you can have a small embedded webview; yes, a naked web view has no controls.

In your loadView or viewDidLoad method:

UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(...)];
[self.view addSubview:webview];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"foo" withExtension:@"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
[webview release];

This will load a foo.html file that you add to your project as a resource. Alternatively, you can use the loadHTMLString:baseURL: if you want to build up the HTML in code.

Daniel Dickison
I would just add the html file like any other resource - i.e. images, right? or would I have to copy that over to the documents dir after app install? (guess thats only when i would want to edit it)
openfrog
`[NSBundle URLForResource:withExtension:]` gives you the path URL for resources in your app bundle, the same as images you add to the Xcode project. You'll need to get the path in a different way if you want a file in the documents directory.
Daniel Dickison
Cooooooooooooool man! It works! Thanks a lot!
openfrog