开发者社区> 问答> 正文

关于ios webview 加载文字乱码

加载下面的网页后 视频能播放 但是标题文字显示乱码怎么办

 self.web = [[UIWebView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.web.delegate = self;
NSString *strUrl = @"http://124.232.150.72/hhh.html";
NSURL *url = [NSURL URLWithString:strUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.web loadRequest:request];
self.web.scalesPageToFit = YES;
[self.view addSubview:self.web];
效果如下

screenshot !

展开
收起
爵霸 2016-03-11 14:00:25 3373 0
1 条回答
写回答
取消 提交回答
  • wabview加载需要用utf8转码才可以。具体代码如下:

    NSString * strUrl = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:self.urlStr] encoding:NSUTF8StringEncoding error:nil];
    
    [webview loadHTMLString:strUrl baseURL:[NSURL URLWithString:self.urlStr]];
    2019-07-17 18:59:08
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载