user2771150
user2771150

Reputation: 722

Getting Font Size of NSAttributed string

I'm trying to get the font size of an NSAttributedString, however, I'm having trouble doing this. How do you get the font size of an NSAttributedString in objective-c?

Upvotes: 1

Views: 2280

Answers (1)

Amin Negm-Awad
Amin Negm-Awad

Reputation: 16650

An attributed string does not have "a font size". The used font is an attribute, which can vary over the String. Look at your Q: There are two different fonts in one paragraph. (One for the usual text and one for the keywords.)

Therefore you can only ask for the existing attributes (including font) at a specific location. I. e. - attributesAtIndex:effectiveRange: does this job for you. The attribute key for the font is NSFontAttributeName. If yo do not find this key in the attributes dictionary, it is Helvetica(Neue), 12 pt.

Upvotes: 4

Related Questions