我正在学习格式化可编辑的 html 文本并在 UIWebView 中显示
//html文件
<html>
<body>
<div id="content" contenteditable="true" style="font-family: Helvetica">
</div>
</body>
</html>
//加载到WebView
[self.webView loadHTMLString:[[NSString alloc] initWithData:
[[NSFileHandle fileHandleForReadingAtPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]] readDataToEndOfFile] encoding:NSUTF8StringEncoding]
baseURL:[NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]]
];
像b或i这样的一些标签可以通过
-(IBAction)bold:(UIButton *)sender {
[self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('bold')"];
}
-(IBAction)italic:(UIButton *)sender {
[self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('italic')"];
}
我想找到一个命令将当前行文本格式化为h1,h2 .... p或pre标记。
我搜索了很多但仍然卡住了。请给个建议!