How to use NSString drawInRect to centre text?

Posted by Steve Folly on Stack Overflow See other posts from Stack Overflow or by Steve Folly
Published on 2009-01-25T10:34:33Z Indexed on 2010/06/08 2:12 UTC
Read the original article Hit count: 397

Filed under:
|
|

How can I draw a string centred within a rect?

I've started off with: (an extract from the drawRect method of my custom view)

NSString* theString = ...
[theString drawInRect:theRect withAttributes:0];
[theString release];

Now I'm assuming I need to set up some attributes. I've had a look through Apple's Cocoa documentation, but it's a bit overwhelming and can't find anything for how to add paragraph styles to the attributes.

Also, I can only find horizontal alignment, what about vertical alignment?

Thanks.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa