Chris
Chris

Reputation: 27384

Draw text onto bitmap or dynamically onto UI

I am trying to create an iPhone puzzle game, it uses a grid system like Sudoku. I have the puzzle itself being drawn to a Bitmap which is then displayed to the view via a UIViewImage control. Currently I have positioned a UIImageView (which displays the puzzle) onto the ViewController using the interface editor.

What I require now though is "hints" above each column and to the side of each row. Can I draw text directly onto a Bitmap or do I have to do it a different way such as drawing text to the ViewController itself, maybe using a number of Labels? In this case is it possible to dynamically create and position labels onto a view? If so then how do I do that?

Upvotes: 0

Views: 234

Answers (1)

Matic Oblak
Matic Oblak

Reputation: 16774

It might depend on the case but probably in most cases the most simple solution would be to place labels.. You can add them dynamically on any event or loading time by using "alloc" + "initWithFrame" + "addSubView" (onto the view controller.view or imageView). Also you can change text at any time or any other property for that matter. You did not really specify your problem at this matter..

As for adding text to textures/images you have many libraries such as "cocos" to play with but I wouldn't recommend that if you will be changing the text.

Edited to add a snippet:

UILabel *someLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 100.0f, 45.0f)];
someLabel.text = @"some text";
[self.view addSubview:someLabel];
[someLabel release];

This is considered to be written in view controller. You might want to have later reference to that same label for witch you put "UILabel *someLabel;" and move release to dealloc...

Upvotes: 1

Related Questions