Skip to content

A library for constructing and modifying NSAttributedStrings

License

Notifications You must be signed in to change notification settings

joeypatino/textattributes

Repository files navigation

Swift Version Cocoapods platforms License: MIT PRs Welcome

TextAttributes

TextAttributes is a Swift library that simplifies the creation and modification of NSAttributedStrings. Its intuitive, strongly typed API enables easy creation of rich text with attributes such as bold, italic, underlined, colored text and more.

Features

  • Simple, intuitive, and strongly typed API for building complex text attributes
  • Easy application of text attributes such as font, color, kerning, and more
  • Customizable paragraph styles, including indentation, line spacing, and alignment

Requirements

  • iOS 12.0+
  • Swift 5.0+

Installation

CocoaPods

You can use CocoaPods to install TextAttributes by adding it to your Podfile:

platform :ios, '12.0'
use_frameworks!
pod 'TextAttributes', :git => '[email protected]:joeypatino/textattributes.git'

Then, run the pod install command to install the library.

Usage

Here's are some examples of how to use TextAttributes:

Example One

import TextAttributes

let label = UILabel()
let string = "hello world"
let attributedString = string.attributed().mutable
attributedString.addAttribute(.foregroundColor(.red))
attributedString.addAttribute(.font(.boldSystemFont(ofSize: 32.0)))
attributedString.addAttribute(.kern(2.0))
label.attributedText = attributedString

Example Two

import TextAttributes

let label = UILabel()
let string = "hello world"
let attrs = [TextAttribute.foregroundColor(.red), .font(.boldSystemFont(ofSize: 32.0)), .kern(2.0)] 
attributedString.addAttributes(attrs, toOccurencesOfString: "hello")
label.attributedText = attributedString

Example Three

import TextAttributes

let label = UILabel()
let string = "hello world"
let attributedString = string.attributed().mutable
attributedString.addAttribute(.foregroundColor(.red))
attributedString.addAttribute(.font(.boldSystemFont(ofSize: 32.0)))
attributedString.removeAttribute(.foregroundColor, fromOccurencesOfString: "o wor")
label.attributedText = attributedString

Contributing

Contributions to TextAttributes are welcome! If you find a bug or would like to make an improvement, please report it on the project's GitHub page at https://github.com/joeypatino/textattributes.

Meta

Joey Patino – @nsinvalidarg[email protected]

License

TextAttributes is released under the MIT License. See the LICENSE file for details.

About

A library for constructing and modifying NSAttributedStrings

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published