• 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
Cell Size Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cell Size Problem


  • Subject: Cell Size Problem
  • From: Karl Goiser <email@hidden>
  • Date: Sat, 20 Dec 2003 05:13:16 +1100

Hello,

I need to determine the vertical size of some text given a set width so I use NSCell's drawingRectForBounds: method like this:

NSCell *cell = [[NSCell alloc] init];
NSAttributedString *attrStr = [NSAttributedString alloc];
[attrStr initWithString: string attributes: sharedFontAttibutes];
[cell setAttributedStringValue: attrStr];

NSRect proposedRect = NSMakeRect(xLocation, yLocation, viewWidth, 10000.0f);
NSSize expectedTextSize = [cell cellSizeForBounds: proposedRect];

with the idea that expectedTextSize.height will tell how many vertical pixels will be required.


This seems to work fine - except - that if I take something that would wrap to 2 lines in the above way, there is about a 5 pixel width where the above code says that there should be 2 lines, but when drawing it, it only draws on 1 line leaving a whole line empty:

[string drawInRect: rect withAttributes: sharedFontAttibutes];


A work-around seems to be to use the expectedTextSize's width setting when drawing to force the wrap, but this doesn't seem quite right - providing a rectangle where the code says it is going to wrap, but not doing it when it gets do doing the drawing...


Am I doing something wrong?


Thanks in advance,

Karl
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Cell Size Problem
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: NSTextField/View contextual menu also selects
  • Next by Date: Re: NSTextField/View contextual menu also selects
  • Previous by thread: Re: NSTextField/View contextual menu also selects
  • Next by thread: Re: Cell Size Problem
  • Index(es):
    • Date
    • Thread