UIWebView
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
{
IBOutlet UIWebView *webView1;
IBOutlet UITextField *txtField;
}
-(IBAction)goClick:(id)sender;
@end
.m
#import "ViewController.h"
@implementation ViewController
-(IBAction)goClick:(id)sender;
{
NSString *str = txtField.text;
NSString *urlString;
NSRange range = [str rangeOfString:@"http://"];
if(range.location == NSNotFound)
{
urlString = [NSString stringWithFormat:@"http://%@", str];
}
else
urlString = str;
txtField.text = urlString;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 loadRequest:request];
[webView1 setScalesPageToFit:YES];
}
- (void)webViewDidStartLoad:(UIW ebView *)webView
{
NSLog(@"webViewDidStartLoad called");
}
- (void)webViewDidFinishLoad:(UI WebView *)webView
{
NSLog(@"webViewDidFinishLoad called");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"message:[error localizedDescription] delegate:nilcancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
NSLog(@"didFailLoadWithError called and error info is %@",[error userInfo]);
}
-(void)viewDidLoad
{
//Url loading in the WebView
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 setDelegate:self];
[webView1 loadRequest:request];
[webView1 setScalesPageToFit:YES];
/*
//HTML Content
[webView1 loadHTMLString:@"<html><body>< h1>Hello World</h1></body></html>" baseURL:nil];
NSString *path = [[NSBundle mainBundle] pathForResource:@"b" ofType:@"png"];
[webView1 loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
*/
}
@end
No comments:
Post a Comment