1

I'm working with a custom UIableViewCell that has four UILabels inside of it.

What I'm currently struggling with is that for smaller iPhones, I'm able to get the correct portrait layout (the numbers correspond to the label numbers).

enter image description here

What I'm trying to do for larger iPhones (screenshot below is from a 6SPlus) is have label 3 move in the direction of the arrow:

enter image description here

I have three constraints for the third label. My thought was to have one of them set with a priority of 1000 to be the "base constraint", and another, set at 999, to change the spacing of the cell:

enter image description here

However, it doesn't seem to have any effect. How can I alter the position of the third label using constraints based on the size class? Thanks!

EDIT: This is an approximate illustration of what I'm trying to get to:

enter image description here

narner
  • 2,908
  • 3
  • 26
  • 63
  • What do you mean you want it to "move"? Do you want it to be pinned to the label 2? Why don't you just set the horizontal spacing constraint between label 2 and 3, instead of setting constraint between 3 and 4? – almas Mar 14 '16 at 18:41
  • The easiest option is to define a container `UIView` that enlarges left and right (setting a fixed horizontal spacing at each side) and then put the label "3" to center horizontally automatically inside that container view. Each "3" label should have a fixed width, of course, so they look the same. – Alejandro Iván Mar 14 '16 at 18:54
  • @AlejandroIván The one problem with that is that the labels are pulling data from an API, so the values won't always be a fixed length. – narner Mar 14 '16 at 18:59
  • Yeah, but the container view will resize relative to the labels 2 and 4. Then the label 3 simply centers relative to the container. Maybe I'm misunderstanding what you want to do? Could you please explain it? – Alejandro Iván Mar 14 '16 at 19:01
  • @AlejandroIván I guess I just need to have my third label closer to my second label on larger iPhones. – narner Mar 14 '16 at 19:04
  • Closer how? Fixed distance from it? Maybe you could upload a new image with what you expect to achieve (including different "sizes" for different contents). – Alejandro Iván Mar 14 '16 at 19:06
  • @AlejandroIván Yes; just made an edit to the post :) – narner Mar 14 '16 at 19:11

1 Answers1

0

Use a UIStackView and put your labels inside it. The stack view can be configured to distribute evenly your four labels, putting the same amount of space between them regardless of how the width of the table grows or shrinks as it launches on a bigger or smaller phone. Thus, you'll look great everywhere.

(If you're not able to use UIStackView, you can achieve the same effect of even distribution using invisible spacer views.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I would love to do that, but unfortunately the app's minimum target is iOS 8 :/ – narner Mar 14 '16 at 18:47
  • Okay, then use invisible spacer views to achieve the same result. That in fact is what UIStackView effectively does (except that they aren't views, but the effect is the same). – matt Mar 14 '16 at 18:48
  • See my discussion here: http://stackoverflow.com/a/20865342/341994 It's vertical instead of horizontal but the principle is exactly identical. – matt Mar 14 '16 at 18:49
  • I think I'm following what you're saying. Do you have any example project illustrating that at all? – narner Mar 14 '16 at 20:47