我可以使用哪些选项在 iOS 中显示格式化的 C 程序。我现在能想到的是
1.制作一个包含代码的HTML文件,并找到一些CSS来显示在web View 中。 不是一个好的选择,因为我必须手动处理格式设置。
2. 使用某种解析器将其转换成NSAttributedString
,然后显示在UITextView中。
如果正确的选项是 one ,指向任何此类 CSS 或 java 脚本的指针将很有帮助,或者如果选项是 two 是否有可用的此类解析器。
或者有没有其他选择可以达到同样的效果。
最佳答案
在 pretty print 中查找看起来它可以格式化 cpp 请参见以下示例: 您可以尝试将您的代码粘贴到此处并对其进行格式化(如果您不需要动态完成)。然后使用带有 firebug 插件的 Firefox 右键单击该元素,转到根目录并复制 thml。也复制 css 文件(在 CSS 选项卡下你可以找到它们)
<!DOCTYPE html>
<html>
<head>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Example</title>
</head>
<body>
<pre class="prettyprint lang-cpp">
int
foo(int k)
{
if (k < 1 || k > 2) {
printf("out of range\n");
printf("this function requires a value of 1 or 2\n");
} else {
printf("Switching\n");
switch (k) {
case 1:
printf("1\n");
break;
case 2:
printf("2\n");
break;
}
}
}
</pre>
</body>
</html>
关于javascript - 在 iOS 中显示格式化的 C 程序的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16608500/