title: UITableViewAutomaticDimension changes multiple times
body: <p>I have a project that uses iOS's default dynamic font. As so, I'm using <code>UITableViewAutomaticDimension</code> for the height. I'm doing everything programmatically, so I set the constraints for my custom cells.</p>
  
  <h2>My Understanding of Constraints and <code>UITableViewCell</code>s</h2>
  
  <p>From what I can understand about constraints, is that when you apply them to the <code>superView</code>, the attributes that you set to be constrained will be forced to move based on the size of the <code>superView</code>. But if you set the constraints to the <code>contentView</code> of the <code>UITableViewCell</code>, then the attribute that you set the constraints to will force the <code>UITableViewCell</code> to change its height, width, ext.</p>
  
  <h2>CustomTableViewCell</h2>
  
  <pre><code>import SnapKit
  
  lazy var loadingIndicator: UIActivityIndicatorView = {
      let loadingIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
      loadingIndicator.sizeToFit()
  
      loadingIndicator.autoresizingMask = [UIViewAutoresizing.flexibleHeight]
      loadingIndicator.hidesWhenStopped = true
  
      return loadingIndicator
  }()
  
  lazy var logoImageView: UIImageView = {
      let logoImageView = UIImageView()
  
      logoImageView.contentMode = UIViewContentMode.scaleAspectFit
      logoImageView.backgroundColor = UIColor.white
  
      logoImageView.clipsToBounds = true
  
      return logoImageView
  }()
  
  lazy var storeLabel: UILabel = {
      let storeLabel = UILabel()
      storeLabel.sizeToFit()
  
      storeLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
      storeLabel.adjustsFontForContentSizeCategory = true
      storeLabel.textColor = UIColor.lightGray
  
      return storeLabel
  }()
  
  lazy var priceLabel: UILabel = {
      let priceLabel = UILabel()
      priceLabel.sizeToFit()
  
      priceLabel.font = UIFont.preferredFont(forTextStyle: .title1)
      priceLabel.adjustsFontForContentSizeCategory = true
      priceLabel.textColor = UIColor.black
  
      return priceLabel
  }()
  
  lazy private var stackView: UIStackView = {
      let stackView = UIStackView()
      stackView.sizeToFit()
  
      stackView.axis = UILayoutConstraintAxis.vertical
      stackView.alignment = UIStackViewAlignment.leading
      stackView.distribution = UIStackViewDistribution.fill
      stackView.spacing = 0
  
      return stackView
  }()
  
  lazy private var priceStackView: UIStackView = {
      let priceStackView = UIStackView()
      priceStackView.sizeToFit()
  
      priceStackView.axis = UILayoutConstraintAxis.horizontal
      priceStackView.alignment = UIStackViewAlignment.center
      priceStackView.distribution = UIStackViewDistribution.fill
      priceStackView.spacing = 0
  
      return priceStackView
  }()
  
  override func draw(_ rect: CGRect) {
      super.draw(rect)
  
      let margins = contentView.layoutMarginsGuide
  
      contentView.addSubview(logoImageView)
      contentView.addSubview(stackView)
  
      stackView.addArrangedSubview(storeLabel)
      stackView.addArrangedSubview(priceStackView)
  
      priceStackView.addArrangedSubview(loadingIndicator)
      priceStackView.addArrangedSubview(priceLabel)
  
      logoImageView.snp.makeConstraints { (make) in
          make.left.equalTo(layoutMarginsGuide).offset(layoutMargins.left * 0.5)
          make.centerY.height.equalTo(layoutMarginsGuide)
          make.width.equalTo(logoImageView.snp.height)
      }
  
      stackView.snp.makeConstraints { (make) in
          make.left.equalTo(logoImageView.snp.right).offset(layoutMargins.left * 1.5)
          make.right.centerY.equalTo(margins)
          make.height.equalTo(margins).offset(-15)
      }
  }
  </code></pre>
  
  <h2>Output</h2>
  
  <p>Everything should work perfectly fine, but I don't get the <a href="https://i.stack.imgur.com/oQ1uo.png" rel="nofollow noreferrer">desired height</a>.</p>
  
  <p><a href="https://i.stack.imgur.com/qAHdD.png" rel="nofollow noreferrer">First</a> height, a second later the height changes to <a href="https://i.stack.imgur.com/qHmGa.png" rel="nofollow noreferrer">this</a>, and the final desired height is <a href="https://i.stack.imgur.com/oQ1uo.png" rel="nofollow noreferrer">this</a>. Am I setting the constraints wrong, or is this just a general iOS bug?</p>