title: Auto Layout with relative constraints not affecting systemLayoutSizeFittingSize: for UITableViewCell
body: <p>I have a <code>UITableView</code> with dynamic height <code>UITableViewCell</code>s and I'm using auto layout to calculate the heights as per <a href="https://stackoverflow.com/a/18746930/368085">this excellent answer</a> on the topic. So far so good.</p>
  
  <p>I'm adapting the app to work with the larger iPhone (6 and 6 Plus) screen sizes and it's mostly pretty straightforward.</p>
  
  <p>However, in some of my cells I have an image that I want to span the whole width of the cell, and I want the image's height to be proportional to the width of the image (0.55 * the width, to be specific). Up to now I had the width and height of the image hard coded in the auto layout constraints, based on the standard 320px portrait table view width pre iPhone 6/6 Plus.</p>
  
  <p>I thought it would be straightforward to add a relative height constraint like so (I'm using <a href="https://github.com/smileyborg/PureLayout" rel="nofollow noreferrer">PureLayout</a>):</p>
  
  <pre class="lang-c prettyprint-override"><code>[self.myImage autoMatchDimension:ALDimensionHeight 
                       toDimension:ALDimensionWidth 
                            ofView:self 
                    withMultiplier:0.55f 
                          relation:NSLayoutRelationGreaterThanOrEqual];
  </code></pre>
  
  <p>If you're not familiar with PureLayout, this translates to a call to</p>
  
  <p><code>[NSLayoutConstraint constraintWithItem: attribute: relatedBy: toItem: attribute: multiplier: constant:0.0f]</code></p>
  
  <p>There are other constraints that pin it's edges to the superview, which is the <code>UITableViewCell</code> contentView.</p>
  
  <p>However, when I call <code>systemLayoutSizeFittingSize:</code> on the cell's <strong>contentView</strong> it seems to totally ignore the relative height constraint, and the resulting cell height is far too small to fit the image. </p>
  
  <p>If I set an explicit height constraint instead of a relative one, there's no problem. Similarly, if I subclass <code>UIImageView</code> and return an explicit size in <code>intrinsicContentSize</code>, there is no problem.</p>
  
  <p>I even tried the following in my <code>UIImageView</code> subclass:
  </p>
  
  <pre><code>- (void) layoutSubviews {
      [super layoutSubviews];    
      self.intrinsicSizeForAutolayout = self.frame.size;    
      [super layoutSubviews];
  }
  
  - (CGSize)intrinsicContentSize {
      return self.intrinsicSizeForAutolayout;
  }
  </code></pre>
  
  <p>where <strong>intrinsicSizeForAutolayout</strong> is a property I defined for the purpose. I thought this might work similarly to the way that setting <code>preferredMaxLayoutWidth</code> for <code>UILabel</code>s solves a similar problem.</p>
  
  <p>But no. It doesn't work.</p>
  
  <p>It would seem I have little alternative to use ugly screen width checking code to conditionally set a fixed height constraint depending on the screen width, something I really wanted to avoid, as it kind of defeats the purpose of using auto layout in the first place.</p>