• 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
How to get max size of view according to constraints?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to get max size of view according to constraints?


  • Subject: How to get max size of view according to constraints?
  • From: Charles Srstka <email@hidden>
  • Date: Mon, 19 Mar 2012 23:20:19 -0500

As everyone knows, if you have a view with a bunch of subviews and you’ve got NSLayoutConstraints set up for everything, in many cases you might end up with a minimum or maximum size for the view beyond which the constraints are impossible to satisfy, and if you try to resize the view outside these bounds either in IB or in the actual program (if the view is the content view of a resizable window, for example), the resizing will simply stop at those boundaries.

What I am having trouble figuring out is how to resize such a view in code in such a way that it will respect the constraints. If I try just setting a frame using -setFrame: with a rect which has an illegal size, NSView is all too happy to do that, and then I get an exception and a flood of console warnings about how I just broke my constraints. Now, getting the view’s minimum size by calling -fittingSize and adjusting my frame accordingly is easy enough, but some views can have a maximum size imposed by constraints as well, and I’m having trouble finding a way to find out what it is in code.

I know that this has to be possible, since Interface Builder and NSWindow are both able to gracefully handle cases where one tries to set a frame size outside the boundaries of what the constraints allow, but I haven’t been able to find any -maximumSize or -adjustedSizeForSize: type methods, or any way to figure this out short of wrapping -setFrame: in an exception handler. I’m sure it’s gotta be something fairly obvious, and I’ll probably be embarrassed by the answer, but at the moment I’m a bit stuck.

Anyone know how to do this?

Thanks,
Charles
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: How to get max size of view according to constraints?
      • From: Peter Ammon <email@hidden>
    • Re: How to get max size of view according to constraints?
      • From: Richard Somers <email@hidden>
  • Prev by Date: Re: const correctness
  • Next by Date: SSL NSURLConnection to fake-cert server?
  • Previous by thread: Static table view cell no longer loads?
  • Next by thread: Re: How to get max size of view according to constraints?
  • Index(es):
    • Date
    • Thread