On 6 Sep 2009, at 18:37, Quincey Morris wrote:

There are several things wrong with this:

-- You're not accounting for the bounds origin, so it only works if the origin happens to be (0, 0).

OK, do you mean the origin of [self bounds] isn't always (0, 0)? That could explain a few things..


-- Presumably you meant "/ 2" on the y_pos calculation.

Yes.


-- The documentation for "sizeWithAttributes:" says that it returns the size of the "bounding box". That could mean any of several different metrics that could result in the string being drawn a few pixels off from where you'd expect (especially in the Y direction, but also possibly in the X direction).

-- You calculate where you want the vertical *center* of this bounding box to be, but 'drawAtPoint:' puts the baseline at the specified point. The baseline is actually going to be more like 2/3 of the way down the bounding box in general.

I suspect the last one of these is the main reason for your vertical centering being off. Try using 'drawInRect:' instead, with a suitably calculated destination rect.

OK, many thanks for the tips Quincey - should clear up my problems.

Stephen

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to