Latest 1.0.0
Homepage https://github.com/magyarosibotond/AttributedStringTag
License MIT
Platforms ios 8.0, osx 10.10

🖍 AttributedStringTag

About

Small framework for easily applying attributes to NSAttributedString.

Example

Requirements

  • iOS 8.0+ / macOS 10.10+
  • XCode 10.0+
  • Swift 4.2+

Features

  • [x] Match tags and apply attributes to it.

Installation Instructions

Swift Package Manager

.Package(url: "https://github.com/magyarosibotond/AttributedStringTag.git", majorVersion: 1)

CocoaPods

pod 'AttributedStringTag'

Carthage

github "magyarosibotond/AttributedStringTag"

Usage

AttributedStringTag provides two extensions to manipulate your NSAttributedStrings.

You can initialize with a given string and attributes:

let text = "Welcome back <b>John, <c>Logout</c></b>"

label.attributedText = NSAttributedString(string: text,
                                          applyintAttributesForTag: ["b": [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)],
                                                                     "c": [NSAttributedString.Key.foregroundColor: UIColor.red]])

You can also use NSMutableAttributedString and mutate the text afterwards:

let text = "Welcome back <b>John, <c>Logout</c></b>"

label.attributedText = NSMutableAttributedString(string: text)
    .setAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)], forTag: "b")
    .setAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], forTag: "c")

License

AttributedStringTag is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "AttributedStringTag",
    "version": "1.0.0",
    "homepage": "https://github.com/magyarosibotond/AttributedStringTag",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "Botond Magyarosi",
    "summary": "Small framework for easily applying attributes to NSAttributedString.",
    "swift_version": "4.2",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "source": {
        "git": "https://github.com/magyarosibotond/AttributedStringTag.git",
        "tag": "1.0.0"
    },
    "source_files": "Sources/**/*.swift"
}

Pin It on Pinterest

Share This