Swiftpack.co - Package - nacho4d/StringUntagger

StringUntagger

Swift

A simple class to convert tagged strings to attributed strings. This is specially useful when strings are attributed and localized.

Simplest example:

let res = "click <b>here</b> please".attributedString(attributter: [
    "root": [ .foregroundColor: UIColor.blue, .font: UIFont.systemFont(ofSize: 17)],
    "b": [ .font: UIFont.boldSystemFont(ofSize: 17), .underlineStyle: NSUnderlineStyle.double.rawValue ]
])

Will result in:

If "root" is not good for your cases, it can be customized too:

let su = StringUntagger(rootName: "MyCustomRootName")
let res = su.attributedString(from: "start <root>this is the middle</root> end", attributer: [
    "MyCustomRootName": [ .foregroundColor: UIColor.lightGray, .font: UIFont.systemFont(ofSize: 12)],
    "root": [ .foregroundColor: UIColor.blue],
])

There is also a block base API that should give full control. Check the tests to find out more :)

MIT Licence

Github

link
Stars: 0

Dependencies

Used By

Total: 0