StringAttribute 0.3.3

StringAttribute 0.3.3

LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2020
SPMSupports SPM

Maintained by Yudai.hirose.

  • By
  • bannzai


StringAttribute is simple to write about NSAttributedString.


You can write like the one below.

  • Initialize attributed string
 "Hello, world".attributed() // NSAttributedString
  • Attach attributes with method chain
label.attributedText = "Hello, world".attributed()
    .apply(with: .foregroundColor(.white)) // All text to be white color
    .apply(with: .foregroundColor(.blue), in: 0..<5) // "Hello" to be blue color
    .apply(with: [.font(UIFont.boldSystemFont(ofSize: 20)), .foregroundColor(.red)], for: "world") // "world" is to be Bold font and red color
  • Attach paragraph style with method chain
label.attributedText = "Hello, \nworld".attributed()
    .apply(with: .paragraph(.complex([.alignment(.center), .lineSpacing(20)]))) // All line text alignment is center and line space is 20.
    .apply(with: .paragraph(.firstLineHeadIndent(20)), for: "world")  // Containing "world", the head indent of line is 20px


  • Write test
  • Add demo project
  • Add playground sample
  • CocoaPods
  • Carthage


StringAttribute is available under the MIT license. See the LICENSE file for more info.