Re: Help with view constraints
Re: Help with view constraints
- Subject: Re: Help with view constraints
- From: Ken Ferry <email@hidden>
- Date: Fri, 28 Oct 2011 17:30:13 -0700
Hi David,
The question seems a little general to me. Where did you have problems
doing what you wanted to do?
On Fri, Oct 28, 2011 at 4:02 PM, Quincey Morris <
email@hidden> wrote:
> On Oct 28, 2011, at 14:53 , David Catmull wrote:
>
> > - What is the simplest way to adjust the text field's height to fit its
> content?
>
> AFAIK there's no *simple* way to do it perfectly. You can use [NSString
> sizeWithAttributes:] to determine the height but you'll need to match the
> text field's attributes as nearly as you can figure out. Even then, there
> will be edge cases where you're off by one line, because text fields use
> compatibility modes of the text subsystem, which can affect line breaks. If
> you want to get into this a bit deeper, Jerry Krinock has attempted to
> unravel the mystery here:
> http://www.sheepsystems.com/sourceCode/sourceStringGeometrics.html
I think you may have read something involving personal experience into
David's question, but -[NSTextFieldCell cellSizeForBounds:] ought to answer
a question like this accurately for David's case.
> > - How do (or can) I set up constraints so that the window and other
> controls will accommodate that change?
>
> Moving other controls should be straightforward -- add constraints for
> what's above the text field to the top of the text field, and what's below
> to the bottom. You should be able to constrain view heights to the positions
> of their contents, but it will take a bit of mucking around with fixed,
> minimum and maximum sizes/positions, not to mention priorities. (Listening
> to the 2nd half of the WWDC session on this should be helpful.) I don't know
> offhand if resizing the content view via layout will cause the window to
> resize too.
I was a little worried about things coming off like this in the talk, since
we do not spend as much time on the usual case before talking about the rest
of the system. :-)
"Mucking around with priorities" should not be the usual case. Most of the
time you want constraints to be required, which is default.
> OTOH, it may not be worth going to all this trouble. If you've calculated
> the desired text field height, it might be easier just to resize the window
> yourself. If you do it that way, you can get the added height to trickle
> down to (eventually) the text field itself, rather than changing the text
> field and trying to get the difference to bubble up to the window.
Please understand that auto layout is not an "advanced feature", it's a
replacement for the existing layout architecture. Replacement, not
addition.
>
> Also, keep in mind that layout in Xcode is not quire ready for prime time,
> even in 4.2. Don't be surprised if Xcode crashes a lot once you start adding
> manual constraints. (Save early and often.)
>
>
> _______________________________________________
>
> 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
>
_______________________________________________
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