Tutorial by Examples

Swift let webview = UIWebView(frame: CGRect(x: 0, y: 0, width: 320, height: 480)) Objective-C UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //Alternative way of defining frame for UIWebView UIWebView *webview = [[UIWebView alloc] init]; CGRect webviewFr...
Load content in webview from the url Swift webview.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!)) Objective-C [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
Method stopLoading() stops the current loading process of the webview. Swift webview.stopLoading() Objective-C [webview stopLoading];
Swift webview.reload() Objective-C [webview reload];
In many cases, for instance when using web views in table view cells, it's important to determine the content size of the rendered HTML page. After loading the page, this can be calculated in the UIWebViewDelegate delegate method: - (void) webViewDidFinishLoad:(UIWebView *) aWebView { CGRect f...
Web views are useful to load locally generated HTML strings. NSString *html = @"<!DOCTYPE html><html><body>Hello World</body></html>"; [webView loadHTMLString:html baseURL:nil]; Swift let htmlString = "<h1>My First Heading</h1><p&gt...
We can run custom JavaScript on a UIWebView using the method stringByEvaluatingJavaScriptFromString().This method returns the result of running the JavaScript script passed in the script parameter, or nil if the script fails. Swift Load script from String webview.stringByEvaluatingJavaScriptFromS...
Instead of web pages, we can also load the document files into iOS WebView like .pdf, .txt, .doc etc.. loadData method is used to load NSData into webview. Swift //Assuming there is a text file in the project named "home.txt". let localFilePath = NSBundle.mainBundle().pathForResource(&...
In vc.h @interface vc : UIViewController<UIWebViewDelegate> in vc.m - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ if (navigationType == UIWebViewNavigationTypeLinkClicked){...
First, add the HTML File to your Project (If you are asked to choose options for adding the file, select Copy items if needed) The following line of code loads the content of the HTML file into the webView webView.loadRequest(NSURLRequest(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForRe...

Page 1 of 1