Sr.Richie
Sr.Richie

Reputation: 5740

Very basic AutoLayout

In a View Controller I have two UILabels.

I'm trying to start to understand the AutoLayout feature, but I'm finding tutorials using storyboards, complex layouts, scrollViews and other components that are absolutely more complex of what I'm trying to achieve and understand.

This is my very basic setup:

enter image description here

What I simply want - to start to dive in the subject - is:

I have tried to add constraints via the "Pin" option, but with no success at all. Maybe I should put them inside another view to act as a container?

This is a very easy question, but right now this AutoLayout feature is really confusing me. And maybe this can be a good starting point to understand what right now looks to me to be designed by a crazy scientist :)

Upvotes: 2

Views: 142

Answers (2)

Prince Agrawal
Prince Agrawal

Reputation: 3607

I would support @RoboticCat for the statement he made. But I would try to deliver what I learned from those videos.

For first requirement: Ctrl+click on any of the label & drag n drop it on another label. Select "Vertical spacing" option from the popup. this will full fill your first requirement.

For second one: Ctrl+click on top label & drag n drop it on view of viewController. select "Top space..." option from popup.

repeat previous step between bottom label & view. This time select "Bottom space.. " option from popup.

Now navigate to Size Inspector of each label. There you can find the constraints just created. Click them to perform Edit.

Decrease priority of top & bottom constraints to 500 from concerned labels. This will solve your issue.

Let me know if more info needed.. :)

Upvotes: 2

Khawar
Khawar

Reputation: 9241

Put both UILabels in a containerView, and align containerView vertically center.

Upvotes: 2

Related Questions