用于轻松地将属性应用到 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à.)
.Package(url: "https://github.com/magyarosibotond/AttributedStringTag.git", majorVersion: 1)
pod 'AttributedStringTag'
github "magyarosibotond/AttributedStringTag"
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")
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.)