views:

63

answers:

3

I've been at this for awhile, it seems that there's many ways to go about this in quartz 2d:

1) Draw text using core graphics methods...

CGContextSelectFont CGContextSetRGBFillColor CGContextShowTextAtPoint

and on and on, which is horribly low level.

2) using NSString drawAtPoint

(so far the method I like)

NSString* text = @"Hello"; [text drawAtPoint:point withFont:font];

3) using UILabel

I've read this somewhere but not too sure if this is possible. but I'm thinking that instantiating a UILabel within drawRect would be pretty costly as drawRect probably gets called a zillion times. ??


I'm doing ok with 2. (using NSString drawAtPoint) for the moment but I wanted to get some opinions. Again, I'm trying to create text within drawRect (I subclassed a view) because I'm also drawing shapes along with text, what is the right way?

Thanks

A: 

Here's the secret: There is right or wrong way. If it looks right, it is right.

But if one way proves to be bad (e.g. it's too slow), then do it the other way.

And regarding your #1 which you've commented as being "horribly low level". My response to that would be "who cares if it's low level?". Make a text class to wrap all the ways that you know how to render text with.

AlvinfromDiaspar
+1  A: 

#2 is how I generally do it unless I need the more precise control of using CG/CT

Joshua Weinberg
+1  A: 

#1 doesn't support international characters. So, don't use it if you use it to draw texts inputted by a user.

So, please use #2 unless you're absolutely sure that the text only contains standard ASCII characters.

Yuji