UIWebView相关
#import "ViewController.h"
@interface ViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *goBackBtn;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *goForwardBtn;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *webUrl = [NSURL URLWithString:@"http://www.baidu.com"];
[self.webView loadRequest:[NSURLRequest requestWithURL:webUrl]];
self.webView.scalesPageToFit = YES;
self.webView.delegate = self;
}
- (IBAction)goBack:(id)sender {
[self.webView goBack];
}
- (IBAction)goForward:(id)sender {
[self.webView goForward];
}
- (IBAction)refrush:(id)sender {
[self.webView reload];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"%@",request.URL.absoluteString);
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"%s",__func__);
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"%s",__func__);
[self.goBackBtn setEnabled:[self.webView canGoBack]];
[self.goForwardBtn setEnabled:[self.webView canGoForward]];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"%s",__func__);
}
@end