Alex Rivera | Logout

How to draw an UILabel in -drawRect:?

Asked 2010-04-23T09:22:56.830
12

Must I also do all this crazy coordinate system conversion stuff here, or is an UILabel different from an UIImageView drawing in -drawRect: ?

There's a method called - (void)drawTextInRect:(CGRect)rect for that.

BUT the documentation says: "You should not call this method directly. This method should only be overridden by subclasses that want to modify the default drawing behavior for the label’s text."

So? How to draw it then in -drawRect:?

Edit
Report

1 Answer

15

If you perform custom drawing in your view you must not draw UILabel or another UI element but rather draw text itself. NSString has several methods for drawing in current context (look at NSString's UIKit extension docs for more methods):

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font
- (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font
answered 2010-04-23T09:29:52.650

Your Answer