2

I got a weird issue and I suspect it's a bug in UILabel, but I need to be sure first it's not my bug.

The hierarchy and the problem(s): The title label gets small and on multiple lines and the year label is too large, even though there is enough space. The next images will show that.

What's important: Title label is multi-line, the rest are out of the box components. Their content hugging and compression resistances are the same, defaults.

There are two situations when this doesn't happen. 1. If I remove the year label 2. If I embed the title label in a stack view of any kind

So just by doing one of these two changes, the title label resizes properly, which is why I suspect it's an UIKit bug. I tried everything I could think of, including changing content hugging and compression resistances, stack view alignments and distributions, view modes.

Setting the prefferedMaxLayoutWidth for the title label doesn't work because the text is dynamic.

aelveon
  • 132
  • 1
  • 1
  • 9
  • you are using autolayouts? – ibnetariq Nov 18 '15 at 10:33
  • yes, and the only constraints I added are for the big stack view's top, leading and trailing to stick to the view's edges/margins – aelveon Nov 18 '15 at 11:03
  • there are 4 stack views in image on your provided link. To which one, you applied constraints? – ibnetariq Nov 18 '15 at 11:08
  • the top one, that contains all the elements – aelveon Nov 18 '15 at 11:18
  • you need to set constraints for all the Views and subviews. UILabel also counts as subView.First do this and if there are still issues(there might be some) let me know. – ibnetariq Nov 18 '15 at 11:26
  • edit: i actually increased the year label compression resistance, so it won't shrink, but it doesn't affect anything else; the issues still occur with the normal value – aelveon Nov 18 '15 at 11:26
  • what kind of constraints should I add? I thought the point of using stack views is that I no longer need to add all the constraints. also, if I try to add for example a constraint like yearLabel.top = stackView.top, I get a conflicting constraints error, because the stack view add a similar constraint, which I cannot modify or remove – aelveon Nov 18 '15 at 11:30
  • man. you are new to autolayout? – ibnetariq Nov 18 '15 at 11:33
  • pretty much, yes. can you give me a starting point of a constraint I could add? – aelveon Nov 18 '15 at 11:41
  • I can be available for skype after 4:00 PM GMT. meanwhile go through this http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1 – ibnetariq Nov 18 '15 at 11:47
  • 2
    Constraints are not a problem. This is actually a bug with multi-line labels in UIStackView. I encountered it myself and was able to reproduce it pretty easily. The easiest workaround is to embed the multi-line label in a UIStackView of itself, even if it doesn't need one. – Steven Van Impe Dec 28 '15 at 18:34

1 Answers1

2

There is indeed a bug, for which there are at least two workarounds:

  1. Embed the multi-line label into another UIStackView, as Steven Van Impe proposed.
  2. Change its compression resistance to 999 or 1000.

In the end, I was better off not using stack views due to their limitations. Maybe they'll get better with future updates.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
aelveon
  • 132
  • 1
  • 1
  • 9