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

> - 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.

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.

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to