Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Autolayout: Issue with UILabels in a resizing parent view
    text
    copied!<p>I've got a view that contains only a UILabel. This label contains multiline text. The parent has a variable width that can be resized with a pan gesture. My problem is that when I do this resizing the UILabel does not recalculate its height such that all of the content is still visible, it simply cuts it off.</p> <p>I've managed to fix it with a bit of a hack but it is horribly slow to run:</p> <pre><code>- (void)layoutSubviews { CGSize labelSize = [self.labelDescription sizeThatFits:CGSizeMake(self.frame.size.width, FLT_MAX)]; if (self.constraintHeight) { [self removeConstraint:self.constraintHeight]; } self.constraintHeight = [NSLayoutConstraint constraintWithItem:self.labelDescription attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:labelSize.height]; [self addConstraint:self.constraintHeight]; [super layoutSubviews]; } </code></pre> <p>Shouldn't this happen automatically with autolayout? </p> <p><strong>EDIT</strong></p> <p>The structure of my view is:</p> <pre><code>UIScrollView ---&gt; UIView ---&gt; UILabel </code></pre> <p>Here are the constraints on the UIScrollView:</p> <pre><code>&lt;NSLayoutConstraint:0x120c4860 H:|-(&gt;=32)-[DescriptionView:0x85c81c0] (Names: '|':UIScrollView:0x85db650 )&gt;, &lt;NSLayoutConstraint:0x120c48a0 H:|-(32@900)-[DescriptionView:0x85c81c0] priority:900 (Names: '|':UIScrollView:0x85db650 )&gt;, &lt;NSLayoutConstraint:0x120c48e0 H:[DescriptionView:0x85c81c0(&lt;=576)]&gt;, &lt;NSLayoutConstraint:0x120c4920 H:[DescriptionView:0x85c81c0]-(&gt;=32)-| (Names: '|':UIScrollView:0x85db650 )&gt;, &lt;NSLayoutConstraint:0x120c4960 H:[DescriptionView:0x85c81c0]-(32@900)-| priority:900 (Names: '|':UIScrollView:0x85db650 )&gt;, &lt;NSLayoutConstraint:0x8301450 DescriptionView:0x85c81c0.centerX == UIScrollView:0x85db650.centerX&gt;, </code></pre> <p>Here are the constraints on the UIView:</p> <pre><code>&lt;NSLayoutConstraint:0x85c4580 V:|-(0)-[UILabel:0x85bc7b0] (Names: '|':DescriptionView:0x85c81c0 )&gt;, &lt;NSLayoutConstraint:0x85c45c0 H:|-(0)-[UILabel:0x85bc7b0] (Names: '|':DescriptionView:0x85c81c0 )&gt;, &lt;NSLayoutConstraint:0x85c9f80 UILabel:0x85bc7b0.trailing == DescriptionView:0x85c81c0.trailing&gt;, &lt;NSLayoutConstraint:0x85c9fc0 UILabel:0x85bc7b0.centerY == DescriptionView:0x85c81c0.centerY&gt; </code></pre> <p>The UILabel itself has no constraints on it, aside from pinning it to the edges of its parent</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload