Alex Rivera | Logout

iPhone - How to draw text in the middle of a rect

Asked 2009-08-19T21:52:16.910
23

Is there a method to draw text in the middle of a rectangle. I can find various alignments, but nothing I have tried can vertically centre the text in a rect.

Is there a simple method to do this, or is there some way to centre a rectangle and then draw in that?

I'm drawing direct to the CGContext, trying to use NSString::drawWithRect or something similar, as I dont really want to have to add a Label just to render some basic text.

Edit
Report

1 Answer

1

I agree with amagrammer's answer, except for a small change: I use font.lineSize to get the proper height. I assume that sizeWithFont will give you the lineSize as well

answered 2012-12-08T00:40:11.417

Your Answer