Stack108
Stack108

Reputation: 955

xcode auto layout issue

in my swift 2 app i working with auto layout. but at the moment i have a problem, which i can't solve.

it can be a simple problem for you, but for me it is hard to understand.

enter image description here

There is an label in a view controller, which has a vertical center position and a width of 240. I understand the "problem", but i don't know, how can i solve it ...

Upvotes: 0

Views: 209

Answers (3)

TropicalViking
TropicalViking

Reputation: 435

have you tried working the layout options within the ViewController scene ? You can use constraints to adjust how your app would like.

enter image description here

Upvotes: 0

Mike Taverne
Mike Taverne

Reputation: 9362

Auto Layout can be confusing, especially at first. You should take some time to watch or read a good tutorial on the web.

Probably you dragged the label onto the canvas, set some constraints, and then tried to resize the label to look the way you wanted it to.

The problem is that while this changes what you see on the canvas, the constraints haven't changed. The warnings are there to let you know that what you're seeing is not reality.

You can get rid of the warnings easily by right-clicking and choosing the option to fix misplaced views.

What this does is update the canvas to match the constraints you've set. Your label will probably move and change size.

Now, chances are that you won't like what you see after doing this. But the thing to do now is change the constraints, not the label on the canvas.

One thing worth noting is that labels have an intrinsic size. That means that the width and height of the label itself are determined by the text inside.

Typically you only need to set one constraint to position the label horizontally, and another to position it vertically. In fact you might try to see if you can center your label horizontally and vertically first, then proceed to work on positioning it how you really want it.

Upvotes: 1

Frog Tan
Frog Tan

Reputation: 79

i guess you want the label to be placed in the center of the screen, if so, with a width, centerX and centerY constraint will be ok.if u get warning info while the text in the label changing, just fix it by adjust frame.

Upvotes: 0

Related Questions