Latest 1.2.0
Homepage https://github.com/tomvlk/MPFormatter_swift
License MIT
Platforms ios 8.0, tvos 9.0, requires ARC

Build Status

MPFormatter_swift

A ManiaPlanet Color Style parser and formatter for Swift

Installation

To install the formatter you have two options:

CocoaPods

Add the following line to the podfile, do a pod install or update, then use the xcodeworkspace and use with import MPFormatter in your code:

pod 'MPFormatter', '~> 1.0.0'
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()

Latest podspec

{
    "name": "MPFormatter",
    "version": "1.2.0",
    "summary": "ManiaPlanet Style Parser.",
    "description": "ManiaPlanet Style Parser. See Github repo for small documentation and examples on how to use.",
    "homepage": "https://github.com/tomvlk/MPFormatter_swift",
    "license": "MIT",
    "authors": "Tom Valk",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/tomvlk/MPFormatter_swift.git",
        "tag": "1.2.0"
    },
    "source_files": "MPFormatter/*.{h,m,swift}",
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This