Time for action – using our bitmap font for a text field
Follow these steps to display bitmap fonts in SPTextField
:
We need to add another property called
title
inside theDialog.h
file, which is also a pointer toSPTextField
:@property SPTextField *title;
We register our bitmap font, as shown in the following code:
[SPTextField registerBitmapFontFromFile:@"PirateFont.fnt"];
We create and position the
_title
instance with the following lines of code:_title = [SPTextField textFieldWithWidth:background.width * 0.6 height:30.0f text:@"Dialog"]; _title.fontName = @"PirateFont"; _title.color = SP_WHITE; _title.x = 24.0f; _title.y = 26.0f;
We need to add the
_title
instance to the display tree, as shown in the following code:[self addChild:background]; [self addChild:buttonYes]; [self addChild:buttonNo]; [self addChild:_content]; [self addChild:_title];
Inside the
Battlefield.m
file, we replace the default title with a custom one:_dialogAbort = [[Dialog alloc] init]; _dialogAbort.title.text...