天天看點

ios html中文顯示亂碼,ios webview加載本地網頁并解決亂碼問題

例如 NSString *htmlpath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent@"xx.html"];

NSString *htmlstring = [NSString stringWithContentsOfFile:htmlpath];

[webview loadHTMLString:htmlstring baseUrl:nil];

如果需要用本地圖檔的話 BASEURL 路徑設定為自己的RESOURCE

如果有亂碼問題;

//加載本地的html檔案

NSString *resourcePath = [[NSBundle mainBundle] resourcePath];

NSString *filePath = [resourcePath stringByAppendingPathComponent:@"common_problem.html"];

//以utf8的編碼格式加載html内容

NSString *htmlString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

//self.wbProblems.scalesPageToFit = YES;

//将文字内容顯示到webview控件上

[self.wbProblems loadHTMLString: htmlString baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];