Attributed strings are a dictionary API pretending to be typography. As soon as a screen needs two styles in one paragraph, the code turns into range arithmetic that breaks the moment the copy changes or gets localised.
github.com/malcommac/SwiftRichString
SwiftRichString
Create and manipulate attributed, HTML and markdown-like strings on all Apple platforms.
Community maintained·Swift·since 2016
- –stars
- –forks
- –license
- –last push
In one look
let title = Style {
$0.font = SystemFonts.Helvetica_Bold.font(size: 20)
$0.color = "#C89A5B"
}
let text = "Hello World!".set(style: title)What it does
-
Styles as named values
Define a style once, then apply and compose it instead of copying font and colour around.
-
HTML and markdown-like input
Render tagged text into styled attributed strings, ready for localised copy.
-
UIKit and AppKit alike
The same styles behave the same way on both platforms.