3
votes

Is there a way to programmatically detect if a given font is serif or sans serif?

For example, if the user has selected Palatino it's serif. If the user selected Arial, it's sans serif.

I can detect the font name and family name. But I don't see a serif or san serif property for UIFont. Without this, I guess I'd have to set and track a isSerif BOOL manually for every font available to the user?

3

3 Answers

1
votes

In fact there is no attribute of UIFont that hints at the font type. If you are only relying on OS font familys (50+ iOS 6.x) you could easily manage them in a plist with all (future) attributes necessary. For using a third party set of fonts you could read up ttf spec if there is an attribute for (sans) serif fonts. last resort is to check the family or/and font name for »serif« in it, assumed they are named accordingly.

0
votes

There is no property on UIFont that will this explicitly for you. At this point point it might be worth while to add a category to UIFont, but it looks like you will have to set up the mapping on your own.

Might be a good project onto GitHub.

0
votes

You can make a plist with key font name and value a boolean. Here is the list of fonts in iOS