title: UIStackView and truncated Multiline UILabels
body: <p>I want to add several multiline Labels to an <code>UIStackView</code>.</p>
  
  <p>But I always end up my Labels being truncated. As seen in this Screenshot
  <a href="https://i.stack.imgur.com/P1m5w.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/P1m5w.jpg" alt="truncated as it is"></a></p>
  
  <p>But I like to have it more as shown here (my faked Screenshot)
  <a href="https://i.stack.imgur.com/qh0Vr.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/qh0Vr.jpg" alt="truncated as it should be"></a></p>
  
  <p>Here is my Code. First I create the parent/master StackView, put it into an ScrollView (which is tucked to the screen) </p>
  
  <pre><code>    stackView = UIStackView()
      stackView.axis = .Vertical
      stackView.distribution = .Fill
      stackView.spacing = 2
      stackView.translatesAutoresizingMaskIntoConstraints = false
      scrollView.addSubview(stackView)
      NSLayoutConstraint.activateConstraints(stackConstraints)
  
  
      let s1 = createHeaderStackView()
      stackView.insertArrangedSubview(s1, atIndex: 0)
  
      let lbl2 = makeLabel()
      lbl2.text = "Second One"
      stackView.insertArrangedSubview(lbl2, atIndex: 1)
  
      scrollView.setNeedsLayout()
  </code></pre>
  
  <p>while <code>makeLabel</code> and <code>makeButton</code> are just helper functions </p>
  
  <pre><code>func makeButton() -&gt; UIButton {
      let btn = UIButton(type: .Custom)
      btn.backgroundColor = UIColor.lightGrayColor()
      return btn
  }
  
  func makeLabel() -&gt; UILabel {
      let lbl = UILabel()
      lbl.font = UIFont.systemFontOfSize(18)
      lbl.setContentCompressionResistancePriority(1000, forAxis: .Vertical)
      lbl.setContentHuggingPriority(10, forAxis: .Vertical)
      lbl.preferredMaxLayoutWidth = scrollView.frame.width
      lbl.numberOfLines = 0
      lbl.textColor = UIColor.blackColor()
      lbl.backgroundColor = UIColor.redColor()
      return lbl
  }
  </code></pre>
  
  <p>The <code>createHeaderStackView</code>method is to configure my StackView to put inside a StackView with all my header stuff.</p>
  
  <pre><code>func createHeaderStackView() -&gt; UIStackView {
      let lblHeader = makeLabel()
      lblHeader.text = "UIStackView"
      lblHeader.textAlignment = .Center
  
      let lblInfo = makeLabel()
      lblInfo.text = "This is a long text, over several Lines. Because why not and am able to to so, unfortunaltey Stackview thinks I'm not allowed."
      lblInfo.textAlignment = .Natural
      lblInfo.layoutIfNeeded()
  
      let lblInfo2 = makeLabel()
      lblInfo2.text = "This is a seconds long text, over several Lines. Because why not and am able to to so, unfortunaltey Stackview thinks I'm not allowed."
      lblInfo2.textAlignment = .Natural
      lblInfo2.layoutIfNeeded()
  
      let btnPortal = makeButton()
      btnPortal.setTitle("My Button", forState: .Normal)
      btnPortal.addTarget(self, action: "gotoPushWebPortalAction", forControlEvents: .TouchUpInside)
  
      let headerStackView = UIStackView(arrangedSubviews: [lblHeader, btnPortal, lblInfo, lblInfo2])
      headerStackView.axis = .Vertical
      headerStackView.alignment = .Center
      headerStackView.distribution = .Fill
      headerStackView.spacing = 2
      headerStackView.setContentCompressionResistancePriority(1000, forAxis: .Vertical)
      headerStackView.setContentHuggingPriority(10, forAxis: .Vertical)
      headerStackView.setNeedsUpdateConstraints()
      headerStackView.setNeedsLayout()
      //headerStackView.layoutMarginsRelativeArrangement = true
      return headerStackView
  }
  </code></pre>
  
  <p>so to make a long story short: What is needed to adjust my stackviews, so each stackview and therefore label is shown in full glorious size? I tried to compress and hug everything, but it didn't seem to work. And googling <a href="https://www.google.de/search?q=uistackview+uilabel+multiline+truncated&amp;oq=uistackview+&amp;aqs=chrome.4.69i57j69i60l3j69i59l2.4393j0j7&amp;sourceid=chrome&amp;es_sm=119&amp;ie=UTF-8" rel="noreferrer">uistackview uilabel multiline truncated</a> seems to be a dead end, too</p>
  
  <p>I appreciate any help,
  regards Flori</p>