Re: Programmatic autolayout problem
Re: Programmatic autolayout problem
- Subject: Re: Programmatic autolayout problem
- From: Rick Mann <email@hidden>
- Date: Mon, 25 Feb 2013 22:04:26 -0800
Thanks, Kyle!
On Feb 25, 2013, at 21:55 , Kyle Sluder <email@hidden> wrote:
> Specifically, you are adding them to the window's content view, correct? I'll assume so.
Yes, that's correct.
>>
>> I programmatically build a view layout string that looks like this:
>>
>> |[view0][view1]
>
> This leaves the right border undefined. Without sufficient internal constraints on your views (either explicit constraints or ones created by virtue of content hugging), this means their widths will also be undefined.
Now that I know the window will, in fact, resize, I can make that to be |[view0][view1]|
>> as well as individual constraints that look like:
>>
>> V:|[view]
>
> This leaves the bottom border undefined. And as above, barring sufficient internal constraints the heights of these views will be undefined.
Similarly, I can make that V:|[view]|
>> That is, I just want my views to stack left-to-right (ideally, right-to-left on RTL systems), with no space between them. Prior to this, I resize the window to be just big enough for all the views.
>
> If your views constraints fully specify their widths and heights, this step is unnecessary.
>
> Do you intend for your views to completely define their own sizes, or do you want them to react to the size of the window? Your post seems to imply the former.
Correct. My view contains two NSTextFields. I want their own content hugging and compression to define their size, and the additional spacing I put in there to define the containing view's size.
>> Inside each view are a couple of NSTextFields, laid out in IB. What I want to do in IB is something like:
>>
>> |-5-[text1]-5-[text2]-5-|
>>
>> And have the parent view compress all the way down to that, such that the text is never truncated.
>
> This leaves the height of the view unspecified.
Sorry, I didn't add that IB also put in default constraints for the vertical, although I may not have added one at the bottom:
|-y1-[view](not sure if there's anything else here)
>> But what I'm ending up with are these frames:
>>
>> containing view: {{0, 20}, {93, 0}}
>> text1: {{2, -17}, {34, 17}}
>> text2: {{35, -17}, {56, 17}}
>>
>> Note that the containing view height is 0, and the y-coordinate for the labels is -17; so, nothing's visible.
>
> Because the height of your view is unspecified, auto layout picked one of the infinite values of height that satisfied the system: 0.
I thought IB's default constraints would prevent this, but the missing constraints in IB allowed it.
>
>
>>
>> Prior to auto layout, it looks like:
>>
>> containing view: {{0, 0}, {95, 20}}
>> text1: {{2, 3}, {34, 17}}
>> text2: {{35, 3}, {58, 17}}
>>
>> Which is how it's laid out in IB.
>>
>> Can anyone please tell me how to set up the constraints in IB so that the view is as small as it can be, without truncating text or going to 0?
>
> I'd start with a diagram of how you want your window to look. Then draw struts between all the views. Remove unnecessary ones. That'll give you an approximation for the set of constraints you need to install.
>
>
>> A separate question: Is it possible to get the window to expand to just hug the stacked views?
>
> When your constraints are set up correctly, this will happen automatically, as long as the constraints producing that size have priorities greater than 500 (NSLayoutConstraintPriorityThatCanResizeWindow or some such).
Thanks, good to know.
IB defaults a lot of hugging/compression constraints to 250. Do I need to increase those to 501 or more, as well?
--
Rick
_______________________________________________
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