美文网首页
iOS - UIWebView 展示txt 文件 解决乱码及

iOS - UIWebView 展示txt 文件 解决乱码及

作者: HanZhiZzzzz | 来源:发表于2018-08-24 14:55 被阅读0次
        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;
    

    相关文章

      网友评论

          本文标题:iOS - UIWebView 展示txt 文件 解决乱码及

          本文链接:https://www.haomeiwen.com/subject/xenbiftx.html