Ranjit
Ranjit

Reputation: 4636

AutoLayout UITableViewCell

I am working with autoLayout for UITableViewCell

So here is my xib and constraints

enter image description here

Here I set constraints such that tableView has dynamic height

Whenever I run on iphone5, it looks this way correctly which I want

enter image description here

But when I run the same thing on ipad it shows this way

enter image description here

So I am not understanding how to make the ipad version look same as iphone version, Not understanding which constraints I am missing.

Upvotes: 0

Views: 179

Answers (2)

Lord Zsolt
Lord Zsolt

Reputation: 6557

When working with autolayout constraints, formulate what you want into sentences.

Example:

  • I want the yellow view to be pinned to the right.
  • I want the yellow view to be pinned to the top and bottom.
  • I want the yellow view to have width of 50.
  • I want my label to be pinned at the top and bottom.
  • I want my label to be pinned to the left.
  • I want my label to be pinned to my yellow view, with 10 pixels between them. (Thus growing in width along with the superview width).

And there you have all your constraints. Now you just have to add them one by one. Top, Bottom, Right to superview and Width constraint with a constant of 50 for the yellow view. Top, Bottom, Left to superview and Right to Yellow view with constant of 10 constraints.

You've pinned your yellow view to the left of the superview, so on bigger screens, it will grow to fulfill that constraint.

Upvotes: 2

Tim
Tim

Reputation: 60120

It looks like you pinned the left edge of the yellow view to the left edge of the table view cell with a 300pt offset. That means on the iPad, the yellow view is still 300pts offset from the left edge of the screen, and grows to fill the rest of the width available.

What you probably want to do instead is pin the right edge of the yellow view to the right edge of the table view cell with a 0pt offset, then also pin the yellow view's width to its desired size.

Upvotes: 1

Related Questions