Re: Auto layout in XCode 6.4
Re: Auto layout in XCode 6.4
- Subject: Re: Auto layout in XCode 6.4
- From: Conrad Shultz <email@hidden>
- Date: Tue, 25 Aug 2015 13:59:03 -0700
> On Aug 25, 2015, at 4:23 AM, Dave <email@hidden> wrote:
>
> Hi All,
>
> I’m trying to get my head around Auto Layout in XXCode, but can’t seem to figure out some basic things.
>
> I have a sample project with a View made up of two Controls, a Text Field and a Button, like so:
>
> | [TextView] [Button] |
>
> Where | = edge of the View.
>
> It has the following constraints at the moment:
>
> 1. Leading Alignment First Item: Button.Leading Relation: Equal Second Item: TextView.Leading Constant: 8 Priority: 1000 Multiplier: 1
Is this correct? It seems unusual for the button and text view's leading to be related if, as drawn, the button is to the right of the text view. Did you mean that the button's leading to be related to the text view's trailing?
> 2. Vertical Space First Item: Superview.Bottom Relation: Equal Second Item: Button.Bottom Constant: 5 Priority: 1000 Multiplier: 1
> 3. Vertical Space First Item: Button.Top Relation: Equal Second Item: Superview.Top Constant: 5 Priority: 1000 Multiplier: 1
> 4. Baseline Alignment First Item: Button.Baseline Relation: Equal Second Item: TextView.Baseline Constant: 0 Priority: 1000 Multiplier: 1
> 5. Horizontal Space First Item: Superview.Trailing Relation: Equal Second Item: Button.Trailing Constant: 5 Priority: 1000 Multiplier: 1
>
> I now, want to move the button so it’s before the text field, like so:
>
> | [Button] [TextView] |
>
> If I just move the button to the left, it doesn’t work, so I’m guessing I need to change the constraints or somehow get XCode to do it for me?
I assume you mean move in Interface Builder. Once you adopt Auto Layout to position a view it is invalid to try to set its frame in code.
>
> When I click on the Button in XCode, I see that it is hooked to the top, bottom and right edge of the superview and the left edge of the TextView.
>
> How do I change this so that it’s hooked to the top, bottom, and left edge of the superview and the left edge of the TextView?
>
> Is there a good doc that explains how to use XCode to do this?
I'm not sure if you are asking about the mechanics of editing constraints in Interface Builder or what you specifically need to edit.
Assuming you are talking about the latter, conceptually, think about what constraints might conflict with what you are trying to do. Since you are only rearranging horizontally, the vertical constraints won't be an issue, which leaves you with constraints 1 and 5. Looking at these, you probably will need to remove both and create appropriate new constraints after moving the views around.
You may want something like a superview-leading-to-button-leading, a button-trailing-to-text view-leading, and a text view-trailing-to-superview-trailing constraint, but it's hard to be sure without a picture.
-Conrad
_______________________________________________
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