title: Swift UIView widget autolayout not working
body: <p>I have a UIView "widget" (created via a separate XIB file and corresponding Swift sub-class of UIView) that is inserted into the main storyboard so that it can be easily reusable. However, the autolayout constraints added to the widget (XIB) isn't working.</p>
  
  <p>This is how the widget looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/4DNRy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4DNRy.png" alt="What the XIB looks like"></a></p>
  
  <p>The idea is that the 3 metrics (UILabels) are distributed evenly through the widget. Some of the key constraints include:</p>
  
  <ul>
  <li>Vertical align the 2nd and 3rd metrics with first metric</li>
  <li>Ensure 2nd metric is horizontally centered in superview</li>
  <li>Ensure 1st metric is a specific distance from left edge</li>
  <li>Ensure 3rd metric is a specific distance from right edge</li>
  </ul>
  
  <p>And so on...</p>
  
  <p>However, when I run the app, it looks like such constraints aren't imposed after the widget is inserted into the main storyboard. The 3rd metric never shows up, and the 2nd metric isn't centered horizontally. Just to confirm, I added red border around the UIView, so that I can see the entire widget. The entire widget shows up in the superview, just the metrics aren't aligned properly as intended.</p>
  
  <p>Any idea why this is happening? One alternative I'm considering is just putting the metrics directly on the main storyboard view, but I'd rather not do this so that I can reuse the view/code...</p>
  
  <p><strong>Update:</strong></p>
  
  <p>As @Peyman asked, here is a clearer version of the constraints. I've changed the labels to left/center/right to make it easier to correlate the constraints with the actual UI element in the XIB:</p>
  
  <p><a href="https://i.stack.imgur.com/fsO2z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fsO2z.png" alt="Detailed constraints"></a></p>