Swiftpack.co - tomvlk/MPFormatter_swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tomvlk.
tomvlk/MPFormatter_swift 2.0.0
:twisted_rightwards_arrows: ManiaPlanet Color Style parser and formatter for Swift
⭐️ 0
🕓 4 years ago
.package(url: "https://github.com/tomvlk/MPFormatter_swift.git", from: "2.0.0")

Build Status

MPFormatter_swift

A ManiaPlanet Color Style parser and formatter for Swift

Installation

To install the formatter you have two options:

Swift Package Dependency

Add the Github Clone URL as your dependency with XCode wizard to add Swift Package. Use package version 2 and higher.

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()

GitHub

link
Stars: 0
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics