AttributedStringTag 1.0.2

AttributedStringTag 1.0.2

Botond Magyarosi 维护。



  • Botond Magyarosi

🖍AttributedStringTag

关于

一个小型框架,可以轻松将属性应用于 NSAttributedString。

Example

要求

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

特性

  • 匹配标签并对其应用属性。

安装说明

Swift 包管理器

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

CocoaPods

pod 'AttributedStringTag'

Carthage

github "magyarosibotond/AttributedStringTag"

使用方法

AttributedStringTag提供了两个扩展来操作您的NSAttributedStrings。

可以用指定的字符串和属性进行初始化

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]])

也可以使用NSMutableAttributedString并在之后更改文本

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")

许可证

AttributedStringTag使用MIT许可证发布。查看许可证详情