赞
踩
html\htm
pdf,doc,ppt,txt
mp4
-(void)loadRequest:(NSURLRequest *)request;
-(void)reload;
- (void)stopLoading;
- (void)goBack;
- (void)goForward;
@property(nonatomic) UIDataDetectorTypes dataDetectorTypes;
/** 网页控件 */
@property (strong, nonatomic) IBOutlet UIWebView webView;
/ 后退按钮 */
@property (strong, nonatomic) IBOutlet UIBarButtonItem goBack;
/ 前进按钮 */
@property (strong, nonatomic) IBOutlet UIBarButtonItem goForward;
/ 刷新按钮 **/
@property (strong, nonatomic) IBOutlet UIBarButtonItem *fresh;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"/Users/liuhongtao/Desktop/图片"]]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"" withExtension:nil]]];
self.webView.scrollView.contentInset = UIEdgeInsetsMake(40, 0, 0, 0);
self.webView.scalesPageToFit = YES;
/*
UIDataDetectorTypePhoneNumber
UIDataDetectorTypeLink
UIDataDetectorTypeAddress API_AVAILABLE(ios(4.0))
UIDataDetectorTypeCalendarEvent API_AVAILABLE(ios(4.0))
UIDataDetectorTypeShipmentTrackingNumber API_AVAILABLE(ios(10.0))
UIDataDetectorTypeFlightNumber API_AVAILABLE(ios(10.0))
UIDataDetectorTypeLookupSuggestion API_AVAILABLE(ios(10.0))
UIDataDetectorTypeNone
UIDataDetectorTypeAll
*/
self.webView.dataDetectorTypes = UIDataDetectorTypeAll;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//加载网页
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
//设置代理
self.webView.delegate = self;
}
- (IBAction)goBack:(id)sender {
[self.webView goBack];
}
- (IBAction)goForward:(id)sender {
[self.webView goForward];
}
- (IBAction)fresh:(id)sender {
[self.webView reload];
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
self.goBack.enabled = self.webView.canGoBack;
self.goForward.enabled = self.webView.canGoForward;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//拦截图片
//获取当前请求网络的URl
NSString *string = request.URL.absoluteString;
//判断字符串中是否包含image,如果有,不允许访问,返回NO
if ([string containsString:@"image"]) {
return NO;
}
return YES;
}
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。