• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
"Orphaned" words not reported by NSString -boundingRectWithSize...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"Orphaned" words not reported by NSString -boundingRectWithSize...


  • Subject: "Orphaned" words not reported by NSString -boundingRectWithSize...
  • From: Shamyl Zakariya <email@hidden>
  • Date: Fri, 25 May 2007 13:51:38 -0400

I've made a window where messages ( just strings ) stack from top to bottom. The window is fixed width, so if a message is too long it word wraps. Finally, since I show several messages, I have to keep track of how tall each is so I can lay it out correctly.

Now, 99% of the time this works. But when the text is just long enough that a single word wraps to the next line, the reported height for the string doesn't show that line, just the lines up to it. I can better show this with code:

First, here's how I set up the string attributes:

NSMutableParagraphStyle *pstyle = [[NSMutableParagraphStyle alloc] init];
[pstyle setParagraphStyle: [NSParagraphStyle defaultParagraphStyle]];
[pstyle setAlignment: NSCenterTextAlignment];
[pstyle setLineBreakMode: NSLineBreakByWordWrapping];


_textDisplayAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont messageFontOfSize: [NSFont smallSystemFontSize]], NSFontAttributeName,
[NSColor whiteColor], NSForegroundColorAttributeName,
pstyle, NSParagraphStyleAttributeName,
nil] retain];



And here's the method preferredHeight which returns the height needed for the string to display properly:


- (float) preferredHeight
{
NSRect br = [_message boundingRectWithSize: NSMakeSize( _width, 0 ) options:NSStringDrawingUsesLineFragmentOrigin attributes: _textDisplayAttributes];
return br.size.height + (2.0 * _vPad);
}


I have no idea why an orphaned word wouldn't be reported. Am I doing something bone-headed here?

Thanks,

email@hidden
    "obviously, you're not a golfer"
        -- the Dude


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: "Orphaned" words not reported by NSString -boundingRectWithSize...
      • From: Aki Inoue <email@hidden>
  • Prev by Date: "Live" support for aggregate functions (@min, @max, etc)
  • Next by Date: Re: "Live" support for aggregate functions (@min, @max, etc)
  • Previous by thread: Re: "Live" support for aggregate functions (@min, @max, etc)
  • Next by thread: Re: "Orphaned" words not reported by NSString -boundingRectWithSize...
  • Index(es):
    • Date
    • Thread