#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *webView;
@end
#import "ViewController.h"
@interfaceViewController ()
@end
@implementation ViewController
/* UIWebViewDelegate 协议的optional方法*/
- (void)webViewDidStartLoad:(UIWebView *)webView{
[[UIApplicationsharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[[UIApplicationsharedApplication] setNetworkActivityIndicatorVisible:NO]; }
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)viewDidLoad
{
[superviewDidLoad];
self.webView = [[UIWebViewalloc] initWithFrame:self.view.bounds];
self.webView.scalesPageToFit = YES;
[self.view addSubview:self.webView];
//NSString *htmlString = @"The first <strong>webView</strong>";
NSURL *url = [NSURLURLWithString:@"http://www.apple.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
//[self.webView loadHTMLString:htmlString baseURL:nil];
// UIWebView类的loading 方法:
// loadData:MIMEType:textEncodingName:baseURL:load an instance of NSData
// loadHTMLString:baseURL:load an instance of NSString,which the web browser can read.
// loadRequest:load an instance of NSURLRequest, help you to load the contents of a remote URL into a web.
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
}
@end