MPFormatter 1.2.0

MPFormatter 1.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Tom Valk.



  • By
  • Tom Valk

Build Status

MPFormatter_swift

A ManiaPlanet Color Style parser and formatter for Swift

Installation

To install the formatter you have two options:

Manual
  1. Copy the files to a directory in your project folder
  2. Drag and drop the xcodeproj file to the project navigator, just under your app project
  3. Go to your App target
  4. Click on the + in the general tab under embedded binaries
  5. Select MPFormatter and click OK
  6. Now you can use MPFormatter with import MPFormatter

Usage

To use the framework:

To get the NSAttributedString from a styled nickname for example, use:

    let nickname = "$F80$i$S$oToffe$z$06FSmurf $z$n$l[http://goo.gl/y4M9VK][App]$l"
    let styledNickname = MPFormatter().parse(nickname).getAttributedString()

This will result in: Example result from above code

You can also strip links, styles or colors with

    let nickname = "$F80$i$S$oToffe$z$06FSmurf $z$n$l[http://goo.gl/y4M9VK][App]$l"
    let noLinks = MPFormatter().parse(nickname).stripLinks().getAttributedString()
    let noColors = MPFormatter().parse(nickname).stripColors().getAttributedString()
    let plainString:String = MPFormatter().parse(nickname).getString() // Get plain string, without any styles

    // Get nickname with font size 11
    let tinyNickname = MPFormatter(fontSize: CGFloat(11)).parse(nickname).getAttributedString()