html - 基本 HTML - 应用 div id

标签 html ios uiwebview

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

最佳答案

你在 head 部分放了一个 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];

关于html - 基本 HTML - 应用 div id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10742726/

相关文章:

javascript - 在加载body之前完成加载外部js?

javascript - 使用 JavaScript 在 HTML 中查找输入

ios - 向 TabBar 应用程序添加 UI 导航

ios - UIView 动画将 View 重置为原始矩形

ios - 模态 ViewController 内的 Youtube 视频,奇怪的崩溃 'UIViewControllerHierarchyInconsistency'

html - 如何使面板的高度随位置相对增长

javascript - 如何以编程方式查找 svg 的大小?

ios - 使用 transient 属性对 UITableView 部分进行排序

ios - 使用任何人的 sdk 或 PHPhotolibrary 在 Instagram 上共享图像?

iOS UIWebView 应用内购买不起作用