sizeToFit without actually changing the size?

  • Is there any way to obtain the size that -sizeToFit will set my view to,
    without actually having it set the size?

    (I can get the view's frame and then change the frame back to its old
    frame after -sizeToFit is done, but that seems like I'm going the long
    way around…)
  • Could you calculate the extents of the things the view contains, using
    their origins and sizes, perhaps?

    --
    m-s

    On 20 Nov, 2007, at 16:40, John Stiles wrote:

    > Is there any way to obtain the size that -sizeToFit will set my view
    > to, without actually having it set the size?
    >
    > (I can get the view's frame and then change the frame back to its
    > old frame after -sizeToFit is done, but that seems like I'm going
    > the long way around…)
  • It's a checkbox and I want to know how wide it will need to be if I
    change its title—not exactly sure how I would do that.

    Michael Watson wrote:
    > Could you calculate the extents of the things the view contains, using
    > their origins and sizes, perhaps?
    >
    >
    > --
    > m-s
    >
    > On 20 Nov, 2007, at 16:40, John Stiles wrote:
    >
    >> Is there any way to obtain the size that -sizeToFit will set my view
    >> to, without actually having it set the size?
    >>
    >> (I can get the view's frame and then change the frame back to its old
    >> frame after -sizeToFit is done, but that seems like I'm going the
    >> long way around…)
    >
  • On Nov 20, 2007, at 4:56 PM, John Stiles wrote:

    > It's a checkbox and I want to know how wide it will need to be if I
    > change its title—not exactly sure how I would do that.

    Try using:

    NSSize theSize = [[theCheckbox cell] cellSize];

    When writing all my custom controls, I implement cellSize in their
    cells to return a proper value.  IB's "size to fit" operation then
    uses that info.  Sounds like you want to do the same thing, but
    programatically? (I'm assuming this thread is related to the "building
    checkboxes programatically" thread).

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • This worked perfectly. Thanks.

    The reference docs for cellSize don't really make this clear—they imply
    that it only works for cells containing text or an image, and subclassed
    cell types like NSButtonCell don't clarify that -cellSize will actually
    work properly. But sure enough, it provides the same result as calling
    -sizeToFit and then reading back the resultant size.

    Ricky Sharp wrote:
    >
    > On Nov 20, 2007, at 4:56 PM, John Stiles wrote:
    >
    >> It's a checkbox and I want to know how wide it will need to be if I
    >> change its title—not exactly sure how I would do that.
    >
    > Try using:
    >
    > NSSize theSize = [[theCheckbox cell] cellSize];
    >
    > When writing all my custom controls, I implement cellSize in their
    > cells to return a proper value.  IB's "size to fit" operation then
    > uses that info.  Sounds like you want to do the same thing, but
    > programatically? (I'm assuming this thread is related to the "building
    > checkboxes programatically" thread).
    >
    > ___________________________________________________________
    > Ricky A. Sharp        mailto:<rsharp...>
    > Instant Interactive(tm)  http://www.instantinteractive.com
    >
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today