If I run this code (on the iPhone):
NSArray *names = [UIFont familyNames];
NSLog(@"Font FamilyNames");
for (NSString *name in names) {
NSLog(@"Font Family: %@",name);
NSArray *fontFaces = [UIFont fontNamesForFamilyName:name];
for (NSString *fname in fontFaces) {
NSLog(@" %@",fname);
}
}
I get this output (abridged):
...
Font Family: Georgia
Georgia-BoldItalic
Georgia-Bold
Georgia-Italic
Georgia
Font Family: Helvetica Neue
HelveticaNeue-BoldItalic
HelveticaNeue-Light
HelveticaNeue-Italic
HelveticaNeue-UltraLightItalic
HelveticaNeue-CondensedBold
HelveticaNeue-MediumItalic
HelveticaNeue-Thin
HelveticaNeue-Medium
HelveticaNeue-ThinItalic
HelveticaNeue-LightItalic
HelveticaNeue-UltraLight
HelveticaNeue-Bold
HelveticaNeue
HelveticaNeue-CondensedBlack
Font Family: Gill Sans
GillSans
GillSans-Italic
...
You can see that each font family has various fonts, but the font names are anything but user-friendly. For example, TextEdit presents them in a much better way:
How can I in a stable way (meaning it works on all fonts, even fonts not yet available on iOS) get the names for each font like TextEdit?
The only thing that comes to mind is to parse each font face name, turning HelveticaNeue-CondensedBold
into Condensed Bold
and HelveticaNeue-UltraLightItalic
into Ultra Light Italic
. However, you'll notice that TextEdit presents HelveticaNeue-UltraLightItalic
as UltraLight Italic
, not Ultra Light Italic
and I'm not sure this method works for all fonts...
Examples of fonts that would not work well with my idea:
Font Family: Bodoni 72
BodoniSvtyTwoITCTT-Book
BodoniSvtyTwoITCTT-Bold
BodoniSvtyTwoITCTT-BookIta
(Bodoni 72
!= BodoniSvtyTwoITCTT
)
Font Family: Times New Roman
TimesNewRomanPS-BoldItalicMT
TimesNewRomanPSMT
TimesNewRomanPS-BoldMT
TimesNewRomanPS-ItalicMT
(Times New Roman
!= TimesNewRomanPS
and what's up with that MT?)
Other problem with it: No font face name contains Regular
, but that is what users expect to see in the options (see the TextEdit screenshot).