MGFormatter
MGFormatter可以以自定义关键字颜色和字体在视图中格式化JSON或HTML代码。
示例
要运行示例项目,请克隆仓库,并首先从Example目录运行 pod install
。
要求
- iOS 8.0+
- Xcode 9.0+
用法
只需创建一个 FormatterView 并设置要格式化的代码。
formatterView.format(string: utf8Text, style: .jsonDark)
关于样式
以下样式可以被开发者自定义。
- 格式化器类型(JSON 或 HTML)和关键字的颜色。
- 字体。
- 行间距。
可以直接使用深色和浅色样式。
支持代码样式和颜色
以下关键字的颜色可以自定义。
- JSON 类型
- 常规
- 属性
- 布尔型
- 字符串
- 数值
- HTML
- 常规
- 标签
- 属性名
- 属性值
以下是自定义样式的示例代码。
let color = JSONColor(
normal: .white,
attribute: .yellow,
boolean: .green,
string: .cyan,
number: .orange
)
let style = FormatterStyle(font: UIFont.systemFont(ofSize: 12), lineSpacing: 5, type: .json(JSONColor()))
self.formatterView.format(string: utf8Text, style: style)
安装
MGFormatter 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'MGFormatter'
作者
许可证
MGFormatter 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。