Swiftpack.co -  octree/AttributedText as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
octree/AttributedText
An elegant way to build NSAttributedString just like SwiftUI.
.package(url: "https://github.com/octree/AttributedText.git", from: "1.0.3")

AttributedText

An elegant way to build NSAttributedString like SwiftUI.

Power by swift Result Builder

Usage

let list = ["hello", "world"]

let attributedText: NSAttributedString = .Builder {
  "@resultBuilder".bold.italic.foreground(color: .purple)
  if #available(iOS 14, *) {
    "Wow".lineHeight(20)
  }
}
.build()

Attachment and Loops

let list = ["谈笑风生", "香港记者", "人生经验", "无可奉告", "身经百战", "亦可赛艇", "图样图森破", "另请高明"]
textView.attributedText = .Builder {
  Group {
    attachment
    " Result builder is awesome\n".bold
        .fontSize(24)
        .foreground(color: .label)
  }
  .lineSpacing(8)

  for element in list {
    element.font(.systemFont(ofSize: 16))
        .foreground(color: .random)
        .lineSpacing(4)
  }
}
.build()

attachment

Installation

Swift Package Manager

License

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

GitHub

link
Stars: 3
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API