title: AutoLayout: multiline label and fixed-size button
body: <p>I'm trying to replicate the following layout from the Kayak app:
  <a href="https://i.stack.imgur.com/pGjoQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pGjoQ.png" alt="kayak app"></a></p>
  
  <p>The layout consists of <em>UICollectionViewCell</em> with a <em>UILabel</em> and a <em>INUIAddVoiceShortcutButton</em>.</p>
  
  <p>However, in my implementation the label doesn't force the cell to stretch further when the text doesn't fit:
  <a href="https://i.stack.imgur.com/DYpU8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DYpU8.png" alt="Clipping text"></a></p>
  
  <p><strong>How could I make the <em>UICollectionViewCell</em> grow with the label, and not truncate the label to the size of the cell?</strong></p>
  
  <p>The whole code for the cell:</p>
  
  <pre><code>final class AddToSiriCell: CornerMaskCellBase {
    lazy var button: INUIAddVoiceShortcutButton = {
      let b = INUIAddVoiceShortcutButton(style: .whiteOutline)
      return b
    }()
  
    lazy var textLabel: UILabel = {
      let label = UILabel()
      label.numberOfLines = 0
      return label
    }()
  
    override init(frame: CGRect) {
      super.init(frame: frame)
      configureViews()
    }
  
    required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
    }
  
    private func configureViews() {
      textLabel.text = "View balance with your pre-recorded Siri Command .View balance with your pre-recorded Siri Command  View balance with your pre-recorded Siri Command View balance with your pre-recorded Siri Command "
      contentView.backgroundColor = .white
      [button, textLabel].forEach(contentView.addSubview)
      button.snp.makeConstraints { (make) in
        make.top.bottom.trailing.equalTo(contentView.layoutMarginsGuide)
      }
  
      textLabel.snp.makeConstraints { (make) in
        make.top.bottom.leading.equalTo(contentView.layoutMarginsGuide).priority(.required)
        make.trailing.equalTo(button.snp.leading).priority(.required)
      }
    }
  }
  </code></pre>
  
  <p><strong>Update 1: Added "Base Class" with fixed width</strong>
  Here is the base class I use for all the cells in the UICollectionView:</p>
  
  <pre><code>import UIKit
  import SnapKit
  
  class AutoSizingCellBase: UICollectionViewCell {
    override class var requiresConstraintBasedLayout: Bool {
      return true
    }
  
    private final var widthConstraint: Constraint?
  
    override init(frame: CGRect) {
      super.init(frame: frame)
      contentView.layoutMargins = UIEdgeInsets(padding: 14)
    }
  
    required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
    }
  
    override func updateConstraints() {
      if widthConstraint == nil {
        if let window = window {
          let width = window.bounds.width - 16
          contentView.snp.makeConstraints { (make) in
            widthConstraint = make.width.equalTo(width).priority(.required).constraint
          }
        }
        contentView.translatesAutoresizingMaskIntoConstraints = true
      }
      super.updateConstraints()
    }
  }
  </code></pre>