views:

52

answers:

2

Is there any SIMPLE way of rendering formatted text (from a char* buffer) to the display...? And I mean, simple.... In C or C++ or even Java, on nearly any platform, including embedded, you can get a pointer to a framebuffer or display and render simple text or pixels with 2 or 3, 5 max lines of code....

I have been looking in across the web (and in iphone development books) but I have yet to see any rendering of text to the display, without going through a whole host of "UI~something~Views" to put a couple lines of text on the screen...

Please tell me I am wrong, and there is a very simple way to render text, nothing fancy, just two or three lines of plain old ascii text, no bells and whistles, just black and white text....

Something like: void my_callback() { Global_Pointer_to_screen(x,y,data); }

Thank you!

+1  A: 

Use a UILabel to render text. Nothing fancy:

NSString *myString = [NSString stringWithCString:myCString encoding:NSUTF8Encoding];
UILabel myLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.bounds.size.width/2), 0.0, 100.0, 50.0) ];
[self addSubview:myLabel];
myLabel.text = myString;

The above code really isn't that difficult to implement. I'm not really sure why you want to write directly to the display buffer. I'm not even sure you can do this at all. I'm pretty sure Apple don't provide a way to do this unless you are using OpenGL. Even then you can't get a pointer to the display and write to the graphics memory using a pointer as far as i know.

I'd strongly advise you to learn UIViews and to do it the proper way.

Brock Woolf
Using IB makes this even easier...
jtbandes
@jtbandes: It does. But he was asking for code.
Brock Woolf
I didn't see anything in the question suggesting he doesn't want to use IB; it's possible he doesn't know much about it.
jtbandes
ChinaSailor
A: 

You can use UILabels in drawRect: to draw a formatted string into a specific location, you just set the frame and manually call drawRect on the label.

Or you can also use Quart2D to render text to the display as well:

http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_text/dq_text.html

As you can see you have a variety of methods to configure the text you are drawing.

But mostly people simple make UILabels in InterfaceBuilder and then they go on the screen.

In iOS4.x+, you have NSAttributedString that you can use to do real formatted text. But it's pretty complex.

Kendall Helmstetter Gelner
Good stuff, thank you!
ChinaSailor