UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, Kk_NaivagationMargin, self.view.bounds.size.width, self.view.bounds.size.height - Kk_NaivagationMargin)];
webView.delegate = self;
webView.backgroundColor = [UIColor clearColor];
[self.view addSubview:webView];
if ([self.fileType isEqualToString:@"txt"]) {
NSData *txtData = [NSData dataWithContentsOfFile:fileUrl];
//自定义一个编码方式
[webView loadData:txtData MIMEType:@"text/txt" textEncodingName:@"GBK" baseURL:nil];
}else{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:fileUrl]];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
mutableRequest.timeoutInterval = 60;
request = [mutableRequest copy]; //拷贝回去
[webView loadRequest:request];
}
self.webView = webView;
网友评论