使用UIWebView载入本地或远程server上的网页
當然你也能夠先從本地讀取html代碼,然后載入。
請注意baseURL地址文件夾要正確,否則html中引用的資源是找不到的。 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"kline71" ofType:@"html" inDirectory:@"XiangJie"]; NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; NSString *baseURL = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"XiangJie/img"]; [_myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:baseURL]]; - (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL; 這個接口用于載入html文件。
MIMEType值一般為"text/html"。相同。請注意baseURL地址文件夾要正確。否則html中引用的資源是找不到的。 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"kline71" ofType:@"html" inDirectory:@"XiangJie"]; NSData *data = [NSData dataWithContentsOfFile:filePath]; NSString *baseURL = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"XiangJie/img"]; [self.myWebView loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:baseURL]];
轉載于:https://www.cnblogs.com/lxjshuju/p/7203103.html
總結
以上是生活随笔為你收集整理的使用UIWebView载入本地或远程server上的网页的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: mysql获取相隔时间段的数据
 - 下一篇: 林俊杰最好听的十首歌