0
 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 idmain应用于我的内容,但我不知道如何让它工作。我认为有问题的行是:“<div id='main' style type=\"text/css\"> \n"但我不确定如何调整它以使其工作?

4

4 回答 4

2

你把一个 div 放在 head 部分,那是行不通的

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];
于 2012-05-24T17:53:47.360 回答
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];
于 2012-05-24T17:54:39.077 回答
1

那条线没有任何意义。我相信你的意思是:

"<div id='main'><style type=\"text/css\"> \n"
于 2012-05-24T17:54:23.770 回答
0

div 作为 head 的子级无效。它应该是身体的孩子

于 2012-05-24T17:53:50.400 回答