iOS8加载css样式失败

前提:WKWebView 加载网络html和本地css样式,在最新版本iOS12和iOS10都没有发现问题,在iOS8上遇到css样式完全没有显示出来

解决办法:通过查看得知,是css文件的类型在iOS8上不支持,需要添加DOM前缀,做法:把css文件以二进制方式打开,在文件的开头加上3个字节 EF BB BF ,然后保存,这样就加上了BOM头。

题外:WKWebView 如何加载css文件

NSString *html = @"要加载的html数据";
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
//获取本地css目录 basePath
NSString *basePath = [NSString stringWithFormat:@"%@/css/", bundlePath];
//获取本地css目录 baseUrl
NSURL *baseUrl = [NSURL fileURLWithPath: basePath isDirectory: YES];

[self.webView loadHTMLString:html baseURL:baseUrl];

猜你喜欢

转载自blog.csdn.net/weixin_34007879/article/details/87163341
今日推荐