malcommac / SwiftRichString

👩‍🎨 Elegant Attributed String composition in Swift sauce
MIT License
3.13k stars 211 forks source link

How to render a tag based string #46

Closed hunasdf closed 5 years ago

hunasdf commented 6 years ago

Hi,

Is it support nested tags? For example:

<red><13>SomeText</13></red>

Thanks!

malcommac commented 6 years ago

Yeah for sure, but tag must start with a letter and not a number.

let baseStyle = Style {
    $0.font = UIFont.systemFont(ofSize: 20)
    $0.color = UIColor.black
}
let redStyle = Style {
    $0.color = UIColor.red
}
let pt13Style = Style {
    $0.font = UIFont.systemFont(ofSize: 13)
}

let group = StyleGroup(base: baseStyle, ["red": redStyle,"p13": pt13Style])
self.textView?.attributedText = "Hello <red><p13>World</p13></red>, Welcome In!".set(style: group)