簡體   English   中英

如何比較NSAttributedString的屬性?

[英]How to compare attributes of a NSAttributedString?

我正在根據某些屬性過濾屬性文本。 有沒有辦法比較if ([attrString.attributes isEqualToDictionary:myAttributes])

您可以使用-enumerateAttributesInRange:options:usingBlock:

在塊中,您可以使用[attrs isEqualToDictionary:myAttributes]測試運行的屬性是否與所需的屬性集完全相同。 警告:如果運行包含您不需要的任何屬性,則返回NO

如果您只想查看myAttributes中的屬性是否已設置(並比較它們的值),而不拒絕其他屬性,請使用[[attrs dictionaryWithValuesForKeys:[myAttributes allKeys]] isEqualToDictionary:myAttributes]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM