Skip to content

Latest commit

 

History

History
114 lines (92 loc) · 2.47 KB

README.md

File metadata and controls

114 lines (92 loc) · 2.47 KB

Swift 4.2.1

Features

  • Comfortable NSAttributedString
  • Better autocompletion
  • Easy range specification
  • Chainable methods
  • Customizable

Installation

Carthage

Add the following line to Cartfile:

github "touyu/SwiftyAttributedString"

Create framework:

$ carthage update --platform iOS

CocoaPods

Add the following line to Podfile:

pod 'SwiftyAttributedString'

Enter the following command at the terminal:

$ pod install

Example

textView.attributedText = "SwiftyAttributedString"
        .attr
        .font(.systemFont(ofSize: 30))
        .range(of: "Swifty") {
            $0.foregroundColor(.blue)
        }
        .range(of: "Attributed") {
            $0.foregroundColor(.red)
            $0.underlineStyle(.single)
        }
        .range(of: "String") {
            $0.foregroundColor(.orange)
            $0.font(.boldSystemFont(ofSize: 30))
        }
        .apply()

Documentation

All Range

"SwiftyAttributedString"
         .attr
         .font(.systemFont(ofSize: 30)) // All range
         .apply()
  

The Specific Range

"SwiftyAttributedString"
         .attr
         .range(start: 0, end: 3) {
              $0.font(.systemFont(ofSize: 30)) // The specific range
         }
         .apply()
  

Customize

"SwiftyAttributedString"
    .attr
    .customize()
    .apply()

extension SwiftyAttributedString {
    func customize() -> SwiftyAttributedString {
        return font(.systemFont(ofSize: 30))
        .range(of: "Swifty") {
            $0.foregroundColor(.blue)
        }
        .range(of: "Attributed") {
            $0.foregroundColor(.red)
            $0.underlineStyle(.single)
        }
        .range(of: "String") {
            $0.foregroundColor(.orange)
            $0.font(.boldSystemFont(ofSize: 30))
        }
    }
}