iOS UIWebView忽略css内联样式
我的UIWebView有问题,它只是忽略了我的样式。它没有任何样式,所有东西似乎都有其默认外观 对这个有什么想法吗?下面您可以找到代码和通用HTML 下面是我加载和呈现html的代码:iOS UIWebView忽略css内联样式,ios,uiwebview,Ios,Uiwebview,我的UIWebView有问题,它只是忽略了我的样式。它没有任何样式,所有东西似乎都有其默认外观 对这个有什么想法吗?下面您可以找到代码和通用HTML 下面是我加载和呈现html的代码: NSStringEncoding encoding; NSString* content; NSString* path = [[NSBundle mainBundle] pathForResource:@"style" ofType:@"css"]; if(path) { content = [NSSt
NSStringEncoding encoding;
NSString* content;
NSString* path = [[NSBundle mainBundle] pathForResource:@"style" ofType:@"css"];
if(path) {
content = [NSString stringWithContentsOfFile:path usedEncoding:&encoding error:NULL];
}
UIFont *systemFont = [UIFont systemFontOfSize:14.0f];
NSMutableString *html = [NSMutableString stringWithString: @"<!DOCTYPE html>\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
"<head>\n"
"<meta charset=\"utf-8\">\n"
"<title>Application</title>\n"
"<style type=\"text/css\">\n"];
if (content) {
NSLog(@" content of css file is %@",[content stringByReplacingOccurrencesOfString:@"%FONT%" withString:[systemFont familyName]]);
} else {
content = @"Could not load content";
}
[html appendString:[content stringByReplacingOccurrencesOfString:@"%FONT%" withString:[systemFont familyName]]];
[html appendString:@"</style>\n"
"</head>\n"
"<body class=\"main\">\n"];
content = nil;
path = [[NSBundle mainBundle] pathForResource:self.contentResource ofType:@"html"];
if(path) {
content = [NSString stringWithContentsOfFile:path usedEncoding:&encoding error:NULL];
} else {
NSLog(@"Couldn't find content resource: %@", self.contentResource);
}
if (content) {
NSLog(@" content of file is %@",content);
} else {
content = @"Could not load content";
}
NSLog(@" webview of this is %@",self.webView);
//continue building the string
[html appendString:content];
[html appendString:@"</body></html>"];
NSLog(@"Full html: %@", html);
//make the background transparent
[self.webView setBackgroundColor:[UIColor clearColor]];
//pass the string to the webview
[self.webView loadHTMLString:content baseURL:nil];
编辑:这里是加载的2个文件,它等于内容(css)文件的日志输出是日志语句
style.css
body,
*,
.main {
font-family: %FONT%, '%FONT%';
font-size: 14px;
color: #FF0000;
}
.heading {
color: #FF9900;
}
a,
a:hover,
a:focus,
a:active,
a:visited {
color: #428bca;
}
contentResource.html
<h4>Info</h4>
<p>Test test test test test test test test test <a href="#ermergency">ermergency</a>.</p>
<p>Still some testing with this</p>
Info
测试测试
还有一些测试
trusted它在web视图中工作正常(使用给定的html和代码)显示NSLog(@“%@”,内容);您测试的是哪种设置?这正是我的代码,没有做任何修改。粘贴了文件的内容。
<h4>Info</h4>
<p>Test test test test test test test test test <a href="#ermergency">ermergency</a>.</p>
<p>Still some testing with this</p>