NSString *HTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0;\">"
"<div id='main' style type=\"text/css\"> \n"
"body {font-family: \"%@\"; font-size: %@; color:rgb(30,30,30); line-height: %ipx;}\n"
"</div> \n"
"</head> \n"
"<body>%@</body> \n"
"</html>", @"helvetica", [NSNumber numberWithInt:[UIFont mainTextFont].pointSize], kWebViewLineSpacing, text];
我正在尝试将div main
应用于我的内容,但我无法弄清楚如何让它工作。我认为有问题的一行是:“<div id='main' style type=\"text/css\"> \n"
但是我不确定如何调整它来运作?
答案 0 :(得分:2)
你在头部放了一个div,这样就行不通了
NSString *HTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0;\">"
"<style type=\"text/css\"> \n"
"body {font-family: \"%@\"; font-size: %@; color:rgb(30,30,30); line-height: %ipx; -webkit-transform: translate3d(0,0,0); word-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; text-overflow: ellipsis; -webkit-text-size-adjust: none; overflow: hidden;}\n"
"</style> \n"
"</head> \n"
"<body><div id=\"main\">My main div</div></body> \n"
"</html>", @"helvetica", [NSNumber numberWithInt:[UIFont mainTextFont].pointSize], kWebViewLineSpacing, text];
答案 1 :(得分:2)
你把东西混在一起,你想要更像
的东西[NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0;\">"
"<style type=\"text/css\"> \n"
"body {font-family: \"%@\"; font-size: %@; color:rgb(30,30,30); line-height: %ipx;}\n"
"</style> \n"
"</head> \n"
"<body><div id='main'>%@</div></body> \n"
"</html>", @"helvetica", [NSNumber numberWithInt:[UIFont mainTextFont].pointSize], kWebViewLineSpacing, text];
答案 2 :(得分:1)
这一行没有任何意义。我相信你的意思是:
"<div id='main'><style type=\"text/css\"> \n"
答案 3 :(得分:0)
div作为头的孩子无效。它应该是身体的孩子