1

I need help to understand how to use autolayout. I watched a couple of videos on youtube and read apples documentation about it but its really hard to grasp how it works.

I have a simple UITableView with a couple of IBOutlets that needs to change positions as there are different sizes of iPhone/iPad. You can see my problem in the image below.

enter image description here

The image to the left is my storyboard, those to pictures to the left shows how it would look like in 4 inch and 4.7 inch.

As you can see the score labels are not visible. How can i fix this.. A step by step guide would be nice since I'm REALLY confused with constraints.. Thanx!!

1
  • Score label set TOP,BOTTOM,TRAILING of Cell and WIDTH,HEIGHT of lebel Commented Jan 9, 2015 at 6:45

1 Answer 1

1

if you do this for the first score label you will define the TOP, TRAILING and BOTTOM constraints of the label so it could know where to place the label. But you still need to define the size of the label with the constraints WIDTH and HEIGHT. You could also define de size of the label using its intrinsic size, but you can start by defining the fixed WIDTH and Height constraints.  1: https://i.sstatic.net/m4YC3.png enter image description here

Then, you need to define the constraints for de second score label. For that you need to define the Bottom and trailing constraints and Width and Height constraints. You don’t need to define the top constraint because it was already defined in the first score label. Check the next figure! =D enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

You used the same pictures? @marciojoaquim
It worked thank you! I got a couple of questions. I dont get it why dont i need to define a top constraint for the second label? The first label's top constraint is from that label to the top container view right?. And the second label's top constraint should be from the label to the other label if im not wrong? Then should not the constraints be different? Also when dealing with constraints. Do i need to put any constraints on the labels to the left like the hometeam, awayteam etc? Seems to be looking good but am i supposed to do it? @marciojoaquim
I have created a new project to demonstrate you this case!
You don't need to create a top constraint because for the first label you have defined a bottom constraint, that basically is a constraint defined between the first and the second labels. So this already defines a constraint for both labels.
Ahhh wonderful! Lol stupid of me that i did not think of that. Where did you learn constraints? Cause i have one other example i am trying to fix and im trying to use the same "thinking" or method but it's not working. @marciojoaquim
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.