Getting bounding rect of NSAttributedString
Getting bounding rect of NSAttributedString
- Subject: Getting bounding rect of NSAttributedString
- From: Simone Manganelli <email@hidden>
- Date: Mon, 24 Jul 2006 20:45:38 -0700
Does anybody know a viable workaround to the continuing problem of
NSAttributedStrings not returning the correct bounding rect? The
boundingRectwithSize:options:attributes method doesn't seem to
respect the attributes that you pass to it, specifically the
NSParagraphStyle telling the text to wrap on words. When actually
drawing the NSAttributedString, the text is correctly word-wrapped,
but I still need the bounding rectangle so that I can center the text
inside an image. For example, the code:
NSMutableParagraphStyle *paragStyle = [[NSMutableParagraphStyle
alloc] init];
[paragStyle setParagraphStyle:[NSParagraphStyle
defaultParagraphStyle]];
[paragStyle setLineBreakMode:NSLineBreakByWordWrapping];
NSDictionary *attributesDict = [[NSDictionary alloc]
initWithObjectsAndKeys:[NSFont fontWithName:@"Helvetica Neue
Condensed Bold" size:12.0],NSFontAttributeName,
paragStyle,NSParagraphStyleAttributeName,
nil];
NSAttributedString *curSquareText = [[NSAttributedString alloc]
initWithString:[curEntry bingoEntryText]
attributes:attributesDict];
NSRect boundsRect = [[curEntry bingoEntryText]
boundingRectWithSize:NSMakeSize(squareWidth,squareHeight)
options:nil attributes:attributesDict];
NSLog(@"max: ò x ò, size: ò x ò",squareWidth, squareHeight,
boundsRect.size.width, boundsRect.size.height);
produces
max: 98.0000002 x 80.0000002, size: 260.0000002 x 19.0000002
which means that the text hasn't been wrapping on words, as it was
specified in the NSParagraphStyle.
I found what was supposed to be a workaround here on the Apple
mailing lists ( http://lists.apple.com/archives/cocoa-dev/2006/Apr/
msg01532.html ), but the workaround does not seem to work for me. It
just returns the same unwrapped size that's outside the bounds of the
specified NSSize.
Any suggestions or other workarounds?
-- Simone
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden