当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - 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?

网友答案:

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.

网友答案:

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.

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: