Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if Font is Serif

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?

like image 804
DenVog Avatar asked Dec 22 '25 16:12

DenVog


1 Answers

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!