UILabel truncates inside UIStackView?

So, using UIStackView, I've noticed that some UILabels seem to want to truncate instead of wrap to a new line... Anyone else noticed this? The label's number of lines is set to 0.


There's a stack view with two labels in it. The stack view is setup to be horizontally and vertically centered in its superview with at least 10 points from the trailing and leading margins. I'd expect the labels to wrap to a new line, not truncate.


Any thoughts?

For some reason the forums aren't uploading my screenshots. So I guess visualize truncated labels. :-)

Stackviews are completely broken when it comes to handling multi-line labels.

Don't know if you're still working on this, but I've found that setting a preferred width on the UILabel helps the stack view layout the label correctly.


The only problem is that when the actual intrensic content width gets very close to the specified preferred width, strange things happen (such as truncating the text when it should wrap instead), but it does help the majority of the time.

Definitely still facing this in the latest beta.


You will notice genres is sized to contain 2 line but it only render a single line. 😟


https://www.dropbox.com/s/384ng4xx7dkrfni/Screenshot%202015-09-03%2007.59.14.png?dl=0

I realize if the character of last line contains character with descent, the line break mod will fail to rendering it correctly.


I'm going to test using attributed string to see if the situation improves.


A quick hack is that in the containing view, after all constraints have been resolve, you can sneakily increase the height


    override public func layoutSubviews() {
        super.layoutSubviews()
        var frame = self.valueLabel.frame
        frame.size.height += 1.0
        self.valueLabel.frame = frame
    }


This will work, but the stack view will still consider the old height, thus you will likely see the descent of the last line being cropped.


https://www.dropbox.com/s/mr5rrdfbhh2n4lk/Screenshot%202015-09-03%2008.15.19.png?dl=0

Set the Distribution in the surrounding StackView to Equal Centering (in the Storyboard). That worked for me.
MFG

UILabel truncates inside UIStackView?
 
 
Q