Create a Web Application, UIWebView
Web Application is an App that is written with HTML,CSS,JavaScript and has a wrapper to be able to show on a device. In this tutorial we will learn how to create a web app. In order to create a web application, follow the bellow steps:
1. create a new project
2. From storyboard, drag and drop WebView from pallet to the view controller
3. Control drag from web View to it's controller to create a property for the webView
4. Drag and drop your HTML files, inside of the project (Make sure you copy as a reference folder)
5. In ViewController inside of viewDidLoad add the following lines:
- (void)viewDidLoad { [super viewDidLoad]; self.webView.delegate = self; self.webView.scalesPageToFit = YES; NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"bootstrap" ofType:@"html"]; NSURL *url = [NSURL fileURLWithPath:htmlFile]; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0.0]; [self.webView loadRequest:request]; }You are done. If you run the application it should show the HTML content.
Show a URL in the WebView
If you want to show a website, you need to change your request like bellow:NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
No comments:
Post a Comment