SwiftRichString – A Swift Library That Simplifies Styling Attributed Strings

SwiftRichString is an open source library submitted by Daniele Margutti that simplifies working with attributed strings.

With SwiftRichString you can style attributed strings using a clear type-safe syntax, combine attributed and non-attributed strings, and more.

This snippet from the readme shows how one could create styles, and apply them to an attributed string with SwiftRichString:

// Define your own used styles
let bold = Style("bold", {
  $0.font = FontAttribute(.CourierNewPS_BoldItalicMT, size: 30) // font + size
  $0.color = UIColor.red // text color
  $0.align = .center // align on center
})

let italic = Style("italic", {
  $0.font = FontAttribute(.CourierNewPS_ItalicMT, size: 25)
  $0.color = UIColor.green
})

let attributedString = ("Hello " + userName).set(style: bold) + "\nwelcome here".set(style: italic)

You can find SwiftRichString on Github here.

A great library for working with attributed strings.

Original article: SwiftRichString – A Swift Library That Simplifies Styling Attributed Strings

©2017 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *