🖍 AttributedStringTag

关于 (Guānyú)

用于轻松地将属性应用到 NSAttributedString 的小型框架。(Yòng yú qīngsōng de jiāng shǔxìng yìngyòng dào NSAttributedString de xiǎoxíng kuàngjià.)

Example

要求 (Yāoqiú)

特性 (Tèxìng)

安装说明 (Ānzhuāng Shuōmíng)

Swift Package Manager

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

CocoaPods

pod 'AttributedStringTag'

Carthage

github "magyarosibotond/AttributedStringTag"

用法 (Yòngfǎ)

AttributedStringTag 提供了两个扩展来操作你的 NSAttributedStrings。(AttributedStringTag tígōng le liǎng gè kuòzhǎn lái cāozuò nǐ de NSAttributedStrings.)

你可以使用给定的字符串和属性进行初始化 (Nǐ kěyǐ shǐyòng gěidìng de zìfúchuàn hé shǔxìng jìnxíng chūshǐhuà)

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 并在之后更改文本 (Nǐ yě kěyǐ shǐyòng NSMutableAttributedString bìng zài zhīhòu gēnggǎi wénběn)

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

许可证 (Xǔkězhèng)

AttributedStringTag 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。(AttributedStringTag zài MIT xǔkězhèng xià fābù. Yǒuguān xiángxì xìnxī, qǐng cān yuè LICENSE.)