1
CSS 스타일 시트가있는 html 문자열의 내용을 UIWebView에로드하는 iOS 앱을 개발하고 있지만 '%'비율을 정의 할 때 문제가 있습니다. 이미지의 너비 그것은 단지 작동하지 않습니다!iOS UIWebView, CSS 및 백분율
문제는 여기에있을 것 같다 :
- (void) loadHTMLContent {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
textFontSize = 120;
NSString *imggt;
if (item.imggt)
imggt = [NSString stringWithFormat:@"<br /><img src='%@' />",item.imggt];
else
imggt = @"";
NSString *cssCode = [NSString stringWithFormat:@" \n"
"body{ font-family: Georgia; color: #333; margin: 0; padding: 0; line-height: 1.2em; } \n"
"h4, h3, h5{ margin: 0 0 5px 0; padding: 0em; text-shadow: 2px 2px 2px rgba(255, 255, 255, 0.8); } \n"
"h3{ font-family: Helvetica; font-size: 1.2em; letter-spacing: -1px; } \n"
"h3, #autor { color: #00365B; } \n"
"h4,h5{ font-weight: normal; font-size: 0.75em; }\n"
"h4{ color: #0069AA; } \n"
"h5{ text-align:justify; } \n"
"#zigzag { height:15px; background-image:url('zigzag.png');background-repeat:repeat-x; }\n"
"#destacados, #cuerpo{ padding: 0 10px; } \n"
"#destacados{ background-image:url('fndNoticia.png'); padding-bottom: 29px; margin-bottom: 0px; } \n"
"#destacados img { width: 97%; text-align:center; margin: 0 auto; border: 8px solid #FFF; } \n"
"#fecha_autor{ font-size: 0.75em; border-bottom: 1px solid #D7D7D7; height: 20px; padding-bottom: 8px; margin: 13px 0; } \n"
"#fecha{ color: #666;} \n"
"#autor{ float: right; } \n"
"#texto{ font-size: 0.80em; line-height: 1.2em; text-align:justify; } \n"];
NSString *htmlCode = [NSString stringWithFormat:@" \n"
"<html> \n"
" <head> \n"
" <title></title> \n"
" <style>%@</style></head> \n" //CSS
" <body> \n"
" <div id='destacados'> \n"
" <br /><h4>%@</h4> \n" //Category
" <h3>%@</h3> \n" //Title
" <h5>%@</h5>%@ \n" //Subtitle & Imggt in HTML
" </div> \n"
" <div id='zigzag'> </div> \n"
" <div id='cuerpo'> \n"
" <div id='fecha_autor'> \n"
" <span id='fecha'>%@</span> \n" //Date
" <span id='author'>%@</span> \n" //Author
" </div> \n"
" <div id='texto'>%@</div> \n"
" </div> \n"
" %@ \n" //Nielsen code
" </body> \n"
"</html> \n",cssCode,item.category,item.title,item.subtitle,imggt,item.pubDate,item.author,[item.text stringByReplacingOccurrencesOfString:@"[br]" withString:@"<br />"],[AppStaticData getNielsenSiteCensusHTMLImageOfArticle:item.url]];
[webView loadHTMLString:htmlCode baseURL:baseURL];
}
브라우저 테스트에서 CSS & HTML 코드가 작동
"#destacados img { width: 97%; text-align:center; margin: 0 auto; border: 8px solid #FFF; } \n"
I가 비율을 사용할 수 없습니다 것 같다 이미지의 값을 설정하십시오. 왜? 원본 이미지를 컨테이너 크기에 상대적으로 에스컬하는 다른 방법이 있습니까?
'당신은 당신의 CSS 코드에서 '%'를 벗어나야합니다 - 이것은 제가 놓친 부분이었습니다. 감사. – kaczor1984