This shows you the differences between two versions of the page.
— | manual_v1:displaying_text [2013/03/05 10:19] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Displaying Text ====== | ||
+ | Displaying text is easy. The class SPTextField should be quite self explanatory. By default, it uses the system fonts of the iPhone. | ||
+ | |||
+ | <code objc> | ||
+ | SPTextField *textField = [SPTextField textFieldWithWidth: | ||
+ | fontName: | ||
+ | textField.hAlign = SPHAlignRight; | ||
+ | textField.vAlign = SPVAlignBottom; | ||
+ | textField.border = YES; | ||
+ | </ | ||
+ | |||
+ | ===== System Fonts ===== | ||
+ | |||
+ | Here is a list of fonts that are installed per default on any iOS version: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **NOTE:** As of iOS 3.2 you can include custom fonts with your project by including the UIAppFonts key (an array of strings with the FULL filename including the extension) in your Info.plist as noted [[https:// | ||
+ | |||
+ | Using system fonts like this is adequate for text that does not change very often. However, if your textfield constantly changes its contents, or if you want to display a fancy font that's not available on the iPhone, you should use a bitmap font instead. | ||
+ | |||
+ | ===== Bitmap Fonts ===== | ||
+ | |||
+ | A bitmap font is a texture containing all the characters you want to display. The positions of the characters are defined in an XML document. This is all Sparrow needs to render a text. To create the necessary files, there are several options: | ||
+ | |||
+ | * There is a great tool provided by the folks from AngelCode that lets you create a bitmap font out of any TrueType font you can imagine: [[http:// | ||
+ | * On OS X, we recommend [[http:// | ||
+ | * Finally, there is a Java program called [[http:// | ||
+ | |||
+ | Whatever tool you choose: after loading a font in that tool, export the font data as an XML file, and the texture in PNG format with white characters on a transparent background (32 bit). The result is a " | ||
+ | |||
+ | To use the bitmap font, just register it at SPTextField: | ||
+ | |||
+ | <code objc> | ||
+ | NSString *bmpFontName = [SPTextField registerBitmapFontFromFile: | ||
+ | </ | ||
+ | |||
+ | This method returns the name of the font as defined in the fnt-file (in the " | ||
+ | |||
+ | <code objc> | ||
+ | textField.fontName = bmpFontName; | ||
+ | </ | ||
+ | |||
+ | That's all you need to do! | ||
+ | |||
+ | By the way: you can add the font PNG to your texture atlas, as well. Just use the following method for registering the font: | ||
+ | |||
+ | <code objc> | ||
+ | NSString *bmpFontName = [SPTextField registerBitmapFontFromFile: | ||
+ | texture: | ||
+ | </ | ||
+ | |||
+ | That way, you save texture space and speed up the rendering. | ||
+ | |||
+ | ----- | ||
+ | |||
+ | //Next section: [[Animation]]// |