PDA

View Full Version : NSString text height


AndrewSage
2004.11.03, 01:25 PM
Can anyone tell me how I can find out the height a piece of text that I display using [text drawInRect:NSMakeRect(0, 0, 200, 300) withAttributes:attr] actually takes up?

Using [text sizeWithAttributes:attr].height only seems to give me the height of the text when it is not drawn within a bounding rectangle.

DoG
2004.11.04, 02:08 AM
I guess you'd have to venture into the hideous realms of NSLayoutManager, NSTextContainer, etc. It is something I struggled with for a while, and finally caved, because a simple hack to what I wanted to do ended up being waaay easier than figuring that crap out.

ThemsAllTook
2004.11.04, 11:32 AM
Yes, I had to do this once... To this day, I still haven't managed to make it work perfectly without either being unstable or leaking memory. This is one of the few things that Cocoa is really bad at doing.

- Alex Diener

AndrewSage
2004.11.04, 12:07 PM
Oh dear it must be very bad if Cocoa cannot do such a simple thing get Windows MFC can :(
Not the kind of news I wanted to hear this close to the 6th November.