Is it possible to get a listing of attributes and ranges for an NSMutableAttributedString?

前端 未结 7 1333
小蘑菇
小蘑菇 2021-02-01 12:36

I\'ve created a method that takes a NSAttributedString and I\'m looking to dynamically create a subview and label to put the string into. Because attributes like font and size n

7条回答
  •  广开言路
    2021-02-01 13:14

    Apple expects you to use enumerateAttributesInRange:options:usingBlock:. The block you supply will receive ranges and the attributes applicable for that range.

    I've used that in my code to create invisible buttons that are placed behind text so that it acts as a hyperlink.

    You could also use enumerateAttribute:inRange:options:usingBlock: if there's only one you're interested in, but no halfway house is provided where you might be interested in, say, two attributes but not every attribute.

提交回复
热议问题