Articles Tagged 'Fonts'

iPhone FontsBook: source code to display the system font

Rounding out the article How To: Custom fonts on iPhone OS 3. 2 I propose the FontsBook sources , a simple iPhone application that shows a table all system fonts, grouped by family.

FontsBookFontsBookFontsBook

Continued ...

How To: Custom fonts on iPhone OS 3.2

With the release 3.2 of IOS you can include your own fonts in an application resource to be used exactly as those supplied with the system:

file. Applications That want to use custom fonts can now include fonts Those In Their application bundle and register with the system by Those fonts Including the UIAppFonts Their key in Info.plist file. The value of this key is an array of strings Identifying the font files in the application's bundle. When The System Sees the key, it loads the specified fonts and Makes Them available to the application.

Continued ...

iPhone: all system fonts

The Apple iPhone provides a limited number of fonts to developers. The list of available fonts is easily achieved by code, as we shall see. If you want to use your own fonts, such as including it in the resources, it is a little more articulate and conivolge also the issue of licenses (rights) fonts "embed" ... we'll talk later. Turning instead to the official sources present in the iPhone they are (click on image to enlarge):

iphonefonts

The Apple iPhone SDK provides access to the special system fonts. These are identified by special constants and are:

1
2
3
[ UIFont boldSystemFontOfSize : 12.0 ] ; UIFont myBoldFont * = [UIFont boldSystemFontOfSize: 12.0];
[ UIFont SystemFontOfSize : 12.0 ] ; UIFont mySystemFont * = [UIFont SystemFontOfSize: 12.0];
[ UIFont italicSystemFontOfSize : 12.0 ] ; UIFont myItalicFont * = [UIFont italicSystemFontOfSize: 12.0];

If you actually get a pointer to a odei fonts shown in the image above just use:

1
[ UIFont fontWithName : @ "Helvetica-Bold" size : 22.0 ] ; UIFont myCustomFont * = [UIFont fontWithName: @ "Helvetica-Bold" size: 22.0];

As you can see the management of the font is special, in addition to the family (Helvetica, Courier, etc ...) must specify the type (bold, italic, etc ...). In practice, therefore, a font must be equipped with these features. The Helvetica, for example, is represented by:

1
2
3
4
Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique

If you want to display your fonts directly on the iPhone, here are some useful code line:

1
2
3
4
5
6
7
8
9
10
11
12
listOfFonts = [ [ NSArray alloc ] initWithArray : [ UIFont familyNames ] ] ; NSArray * listOfFonts = [[ NSArray alloc] initWithArray: [UIFont familyNames]];
subFontTypes; NSArray * subFontTypes;

int i = 0 ; i< [ listOfFonts count ] ; i ++ ) { for (int i = 0; i <[listOfFonts count]; i + +) {
"Font Family: %@" , [ listOfFonts objectAtIndex : i ] ) ; NSLog (@ "Font Family:% @", [listOfFonts objectAtIndex: i]);
NSArray alloc ] initWithArray : [ UIFont fontNamesForFamilyName : [ listOfFonts objectAtIndex : i ] ] ] ; subFontTypes = [[ NSArray alloc] initWithArray: [UIFont fontNamesForFamilyName: [listOfFonts objectAtIndex: i]]];
int j = 0 ; j< [ subFontTypes count ] ; j ++ ) { for (int j = 0 j <[subFontTypes count] j + +) {
"+----->Type: %@" , [ subFontTypes objectAtIndex : j ] ) ; NSLog (@ "+-----> Type:% @ ", [subFontTypes objectAtIndex: j]);
}
; [SubFontTypes release];
}
; [ListOfFonts release];

With the SDK 2.2.1 on my simulator, I got:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Font Family: Courier
+-----> Type: Courier
+-----> Type: Courier-BoldOblique
+-----> Type: Courier-Oblique
+-----> Type: Courier-Bold
Font Family: AppleGothic
+-----> Type: AppleGothic
Font Family: Arial
+-----> Type: ArialMT
+-----> Type: Arial-BoldMT
+-----> Type: Arial-BoldItalicMT
+-----> Type: Arial-ItalicMT
Font Family: sthe TC
+-----> Type: Light-STHeitiTC
+-----> Type: Medium-STHeitiTC
Font Family: Hiragino Kaku Gothic Pron
+-----> Type: HiraKakuProN-W6
+-----> Type: HiraKakuProN-W3
Font Family: Courier New
+-----> Type: CourierNewPS-BoldMT
+-----> Type: CourierNewPS-ItalicMT
+-----> Type: CourierNewPS-BoldItalicMT
+-----> Type: CourierNewPSMT
Font Family: Zapfino
+-----> Type: Zapfino
Font Family: Arial Unicode MS
+-----> Type: ArialUnicodeMS
Font Family: sthe SC
+-----> Type: Medium-STHeitiSC
+-----> Type: Light-STHeitiSC
Font Family: American Typewriter
+-----> Type: AmericanTypewriter
+-----> Type: AmericanTypewriter-Bold
Font Family: Helvetica
+-----> Type: Helvetica-Oblique
+-----> Type: Helvetica-BoldOblique
+-----> Type: Helvetica
+-----> Type: Helvetica-Bold
Font Family: Marker Felt
+-----> Type: Thin-MarkerFelt
Font Family: Helvetica Neue
+-----> Type: HelveticaNeue
+-----> Type: HelveticaNeue-Bold
Font Family: DB LCD Temp
+-----> Type: DBLCDTempBlack
Font Family: Verdana
+-----> Type: Verdana-Bold
+-----> Type: Verdana-BoldItalic
+-----> Type: Verdana
+-----> Type: Verdana-Italic
Font Family: Times New Roman
+-----> Type: TimesNewRomanPSMT
+-----> Type: TimesNewRomanPS-BoldMT
+-----> Type: TimesNewRomanPS-BoldItalicMT
+-----> Type: TimesNewRomanPS-ItalicMT
Font Family: Georgia
+-----> Type: Georgia-Bold
+-----> Type: Georgia
+-----> Type: Georgia-BoldItalic
+-----> Type: Georgia-Italic
Font Family: sthe J
+-----> Type: Medium-STHeitiJ
+-----> Type: Light-STHeitiJ
Font Family: Arial Rounded MT Bold
+-----> Type: ArialRoundedMTBold
Font Family: Trebuchet MS
+-----> Type: TrebuchetMS-Italic
+-----> Type: TrebuchetMS
+-----> Type: Trebuchet-BoldItalic
+-----> Type: TrebuchetMS-Bold
Font Family: sthe K
+-----> Type: Medium-STHeitiK
+-----> Type: Light-STHeitiK

Continued ...