项目作者: lm2343635

项目描述 :
A JSON string formatter running on iOS
高级语言: Swift
项目地址: git://github.com/lm2343635/MGFormatter.git
创建时间: 2017-08-13T06:05:54Z
项目社区:https://github.com/lm2343635/MGFormatter

开源协议:MIT License

下载


MGFormatter

Swift 5.0
build_check
Version
License
Platform

MGFormatter can format the JSON or HTML code in a view with customized keyword color and font.




Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+
  • Xcode 9.0+

Usage

Just create a FormatterView and set the code you want to format.

  1. formatterView.format(string: utf8Text, style: .jsonDark)

About style

The follow style can be customized be the developers.

  • Formatter type(JSON or HTML) and the colors of key words.
  • Font.
  • Line spacing.

Dark and light style can be used directly.

Supported code style and colors

The following colors of keywords can be customized.

  • JSON type
    • normal
    • attribute
    • boolean
    • string
    • number
  • HTML
    • normal
    • tag
    • attribute name
    • attribute value

Here is the demo code for customized style.

  1. let color = JSONColor(
  2. normal: .white,
  3. attribute: .yellow,
  4. boolean: .green,
  5. string: .cyan,
  6. number: .orange
  7. )
  8. let style = FormatterStyle(font: UIFont.systemFont(ofSize: 12), lineSpacing: 5, type: .json(JSONColor()))
  9. self.formatterView.format(string: utf8Text, style: style)

Installation

MGFormatter is available through CocoaPods. To install
it, simply add the following line to your Podfile:

  1. pod 'MGFormatter'

Author

Meng Li, lm2343635@126.com

License

MGFormatter is available under the MIT license. See the LICENSE file for more info.