Latest 0.2
Homepage https://github.com/ysoftware/appendAttributedString
License MIT
Platforms ios 8.0
Authors

append(attributedString, with: ease)

Swift 4.2

An extension that adds a way for easier work with NSMutableAttributedString.

Supports dynamic fonts, colors, underlines, strike through, images and you can chain append calls.
And with the AttributesBuilder class it’s easy to create attribute sets for Attributed String.

Install with Cocoapods:

pod 'appendAttributedString'

Here’s an example:

let textView = UITextView()
let string = NSMutableAttributedString()

// dynamic fonts
string.appendHeadline("Life can rise,n")

    // call chaining
    .appendFootnote("it can fall.nn")

    // color, underline, strike through, superscript and others
    .append("But in the endnit's just carried ", color: .white)
    .append("with the windn", 
        color: .yellow,
        font: .dynamic(.systemFont(ofSize: 10)),
        baselineOffset: 5)
    .append("and one day everything you do will simply cease to be…nn",
        color: .green, 
        underlineStyle: .styleDouble)
    .append("Like a child's ", color: .white)

    // and even images
    .append(image: UIImage(named: "balloon")!,
        height: UIFontMetrics.default.scaledValue(for: 20)) // (the image will not auto-adjust its height)

    // In specal cases use AttributesBuilder class for easier attributes set up
    .append("nnwhen it's lost, it's a tragic affairn",
        withAttributes: AttributesBuilder()
                        .color(.white)
                        .shadow(offset: CGSize(width: 7, height: -5),
                                               blurRadius: 5, color: .yellow)
                        .outline(width: -2, color: .red)
                        .build())

    .append("- but it is quickly forgotten.", withAttributes:
        AttributesBuilder().strikeThrough(.styleSingle, color: .white).build())

textView.attributedText = string

result

Latest podspec

{
    "name": "appendAttributedString",
    "version": "0.2",
    "summary": "An extension for NSMutableAttributedString",
    "description": "An extension that adds a way for easier work with NSMutableAttributedString.nSupports dynamic fonts, colors, underlines, strike through, images and you can chain append calls. And with the AttributesBuilder class it's easy to create attribute sets for Attributed String.",
    "homepage": "https://github.com/ysoftware/appendAttributedString",
    "license": {
        "type": "MIT",
        "file": "MIT-LICENSE.txt"
    },
    "social_media_url": "http://twitter.com/ysoftware",
    "authors": {
        "Yaroslav Erohin": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.2",
    "source": {
        "git": "https://github.com/ysoftware/appendAttributedString.git",
        "tag": "v0.2"
    },
    "exclude_files": "appendAttributedString/appendAttributedStringTests",
    "source_files": "appendAttributedString/**/*.{h,m,swift}"
}

Pin It on Pinterest

Share This