6

I'm new to iOS and trying TableView for the first time.

I added a prototype cell into the TableView. It has label a inside it which is on the right side. When i run it on lower display like 4S, the label is not visible.

I tried setting Horizontal Space - Content View to label (on right side), but has no effect.

I been playing with the auto layout for sometime, but can't figure it out, can someone be kind enough to help me?

Edit:

enter image description here

4 Answers 4

2

Before answering straight, I would say stick to autolayouts and not look for frames, springs and structs.

Now pin UILabel. Select UILabel Go to Editor>pin leading and top space to superview. Also pin the width and height (fix them if you want to). Your problem is solved.

Go through this book for autolayouts and keep playing.- iOS Auto Layout Demystified, 2nd Edition

Updated after question edit :

For Label1 set :

  1. Pin Leading, Top and Bottom Space to superview.
  2. Pin the height(not the width)

For Label1 set :

  1. Pin Trailing, Top and Bottom Space to superview.
  2. Pin the height(not the width) again.

Now select both the labels and go and pin horizontal spacing between them. And if meanwhile you update frame... do update constraint also.

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

4 Comments

sorry, not working, I added everything as you said. Also tried adding trailing space instead of leading space. but still the same effect. I added a screenshot of, after doing what you said. Please see. Label 2 not appearing on screen
I think I found the problem. After changing the display I've to click Update frames. Please tell me how do I solve this When I run the app.
@HeisenBerg kindly follow the steps. now. And thanks for uploading the image this time.
I did what you said. But after changing display by going to View Controller > simulated metrics > size, its not adjusting according to the screesize. Then i if I select the table cell and goto Resolve autolayout > Update Frames. it works. So what can I do to solve this? is there are someway to update frames programatically?
1

give vertical constraints to your label, if there is not that much need of autolayout you can disable autolayout.

Comments

1

The constraint is not enough to determine the vertical position of the label.

Two optional ways:

  • Add the Vertical Center in container constraint
  • Add a height constraint of the label and a top spacing to containe constraint (the contentView of the UITableViewCell your case)

With each of the above and your already exist constraint, the position of the UILabel can be determined exactly.

2 Comments

I think I found the problem. After changing the display I've to click Update frames. Please tell me how do I solve this When I run the app?
@HeisenBerg Updating the frames has nothing to do with the constraints in runtime. It just changes the frame in storyboard. If your constraints are correct, the element will be in right place when you run the app.
0

You can add leading, trailing, top, and height constraints on your label.

1 Comment

I did that, but has no effect

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.