title: UIView not resizing to fit content
body: <p>I have <code>UIView</code> (annotationView), that has 2 UILabels, some separator and 1 image.
  I want to resize the view, so it has minimal size that will fit the elements inside.
  It has constraints to stick to the edges of the view and keep distances between elements.
  <a href="https://i.stack.imgur.com/J9IKg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J9IKg.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/SXEOU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SXEOU.png" alt="enter image description here"></a></p>
  
  <p>When using the <code>annotationView</code>, I simply created <code>UIView</code> and set it's class to annotationView in IB (yellow on the picture below). It has no constraints, but it always show with the size I create it in Interface Builder.</p>
  
  <p><a href="https://i.stack.imgur.com/Dy6oR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dy6oR.png" alt="enter image description here"></a></p>
  
  <p>What should I recheck and set to fit the content with minimal size of view?</p>
  
  <p>My implementation of annotationView:</p>
  
  <pre><code>//used when loading from storyboard
  -(instancetype)initWithCoder:(NSCoder *)aDecoder {
      DLog(@"Initializing ICProgressPlotAnnotationView - from XIB");
      self = [super initWithCoder:aDecoder];
      if (self) {
          [self commonInit];
      }
      return self;
  }
  
  
  - (void)commonInit {
      //load the interface file from .xib
      [[NSBundle mainBundle] loadNibNamed:@"ICProgressPlotAnnotationView" owner:self options:nil];
  
      _view.frame = self.frame;
      [_view setNeedsDisplay]; //view is linked to the main view in .xib see image below
  
      DLog(@"ICProgressPlotAnnotationView VIEW frame: %@", NSStringFromCGRect(self.view.bounds));
      DLog(@"ICProgressPlotAnnotationView frame: %@", NSStringFromCGRect(self.bounds));
      //add as a subview
      [self addSubview:self.view];
  
      [_title_DOWNLabel sizeToFit];
      [_title_UPLabel sizeToFit];
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ufutx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ufutx.png" alt="enter image description here"></a></p>
  
  <p>EDIT1:</p>
  
  <p>Additional info on constraints:
  <a href="https://i.stack.imgur.com/eAo7X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eAo7X.png" alt="enter image description here"></a></p>
  
  <p>EDIT 2:
  Now every time I want to change label, I also call <code>sizeToFit</code> on both labels and <code>_view</code> property in <code>annotationView</code>.</p>
  
  <p>They change sizes properly after that, but <code>_view</code> does not.</p>
  
  <p>Any suggestions?</p>
  
  <p>EDIT 3:
  Also sharing my viewHierarchy:</p>
  
  <pre><code> &lt;ICProgressPlotView: 0x7fff1404d960; frame = (56 60; 263 567); autoresize = RM+BM; layer = &lt;CALayer: 0x7fff11ed4070&gt;&gt;
     |    |    | &lt;UIView: 0x7fff11ee8b60; frame = (0 0; 263 567); autoresize = W+H; layer = &lt;CALayer: 0x7fff11edc9e0&gt;&gt;
     |    |    |    | &lt;ICProgressPlotAnnotationView: 0x7fff11f3e2a0; frame = (0 0; 276 67); autoresize = RM+BM; autoresizesSubviews = NO; layer = &lt;CALayer: 0x7fff11ce49e0&gt;&gt;
     |    |    |    |    | &lt;UIView: 0x7fff14054120; frame = (0 0; 276 67); clipsToBounds = YES; autoresize = W+H; userInteractionEnabled = NO; layer = &lt;CALayer: 0x7fff14054290&gt;&gt;
     |    |    |    |    |    | &lt;UIView: 0x7fff140513e0; frame = (8 32.5; 260 2); clipsToBounds = YES; autoresize = RM+BM; layer = &lt;CALayer: 0x7fff11cb81c0&gt;&gt;
     |    |    |    |    |    | &lt;UILabel: 0x7fff140538a0; frame = (31 8; 27 17); text = '35.1'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = &lt;_UILabelLayer: 0x7fff14053ab0&gt;&gt;
     |    |    |    |    |    | &lt;UIImageView: 0x7fff14054300; frame = (8 9; 15 15); autoresize = RM+BM; userInteractionEnabled = NO; layer = &lt;CALayer: 0x7fff14054730&gt;&gt;
     |    |    |    |    |    | &lt;UILabel: 0x7fff14051740; frame = (8 42.5; 68.5 13.5); text = 'TITLE DOWN'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = &lt;_UILabelLayer: 0x7fff14051d30&gt;&gt;
     |    |    |    | &lt;UIView: 0x7fff11ee8cd0; frame = (8 525; 3.5 13); autoresize = RM+BM; layer = &lt;CALayer: 0x7fff11e0ea50&gt;&gt;
     |    |    |    |    | &lt;UILabel: 0x7fff11ee8e40; frame = (0 0; 3.5 13); text = ' '; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = &lt;_UILabelLayer: 0x7fff11e934d0&gt;&gt;
     |    |    |    | &lt;UILabel: 0x7fff11eece70; frame = (27.5 546; 3.5 13); text = ' '; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = &lt;_UILabelLayer: 0x7fff11e69e00&gt;&gt;
     |    |    |    | &lt;CPTGraphHostingView: 0x7fff11e1f840; frame = (19.5 0; 243.5 538); autoresize = RM+BM; gestureRecognizers = &lt;NSArray: 0x7fff11edc9b0&gt;; layer = &lt;CALayer: 0x7fff11ed1d40&gt;&gt;
     |    |    |    |    | &lt;&lt;CPTXYGraph: 0x7fff11d132d0&gt; bounds: {{0, 0}, {243.5, 538}}&gt; (layer)
     |    |    |    |    |    | &lt;&lt;CPTPlotAreaFrame: 0x7fff11f3c750&gt; bounds: {{0, 0}, {204, 498}}&gt; (layer)
     |    |    |    |    |    |    | &lt;ICProgressPlotView: 0x7fff1404d960; frame = (56 60; 263 567); autoresize = RM+BM; layer = &lt;CALayer: 0x7fff11ed4070&gt;&gt;
     |    |    |    |    |    |    |    | &lt;&lt;CPTGridLineGroup: 0x7fff11ef4380&gt; bounds: {{0, 0}, {204, 498}}&gt; (layer)
     |    |    |    |    |    |    |    | &lt;&lt;CPTGridLineGroup: 0x7fff11ef3b30&gt; bounds: {{0, 0}, {204, 498}}&gt; (layer)
     |    |    |    |    |    |    |    | &lt;&lt;CPTXYAxisSet: 0x7fff11eef990&gt; bounds: {{0, 0}, {0, 0}}&gt; (layer)
     |    |    |    |    |    |    |    |    | &lt;&lt;&lt;CPTXYAxis: 0x7fff11ef0670&gt; bounds: {{0, 0}, {204, 498}}&gt; with range: &lt;&lt;CPTPlotRange: 0x7fff11ef9630&gt; {-0.5, 6}&gt; viewCoordinates: {0, 0} to {204, 0}&gt; (layer)
     |    |    |    |    |    |    |    |    | &lt;&lt;&lt;CPTXYAxis: 0x7fff11ef2840&gt; bounds: {{0, 0}, {204, 498}}&gt; with range: &lt;&lt;CPTPlotRange: 0x7fff11ef96f0&gt; {-10, 120}&gt; viewCoordinates: {20.4, 0} to {20.4, 498}&gt; (layer)
     |    |    |    |    |    |    |    | &lt;&lt;CPTPlotGroup: 0x7fff11e30b80&gt; bounds: {{0, 0}, {204, 498}}&gt; (layer)
     |    |    |    |    |    |    |    |    | &lt;ICProgressPlotView: 0x7fff1404d960; frame = (56 60; 263 567); autoresize = RM+BM; layer = &lt;CALayer: 0x7fff11ed4070&gt;&gt;
     |    |    |    |    |    |    |    |    | &lt;ICProgressPlotView: 0x7fff1404d960; frame = (56 60; 263 567); autoresize = RM+BM; layer = &lt;CALayer: 0x7fff11ed4070&gt;&gt;
     |    | &lt;_UILayoutGuide: 0x7fff11efb100; frame = (0 0; 0 20); hidden = YES; layer = &lt;CALayer: 0x7fff11ef9a60&gt;&gt;
     |    | &lt;_UILayoutGuide: 0x7fff14100000; frame = (0 667; 0 0); hidden = YES; layer = &lt;CALayer: 0x7fff11efbc10&gt;&gt;
  </code></pre>
  
  <p>EDIT 4:
  autolayoutTrace gives results:</p>
  
  <pre><code>(lldb) po [[UIWindow keyWindow] _autolayoutTrace]
  
  •UIWindow:0x7fe600f30900
  |   •UIView:0x7fe600ed3490
  |   |   *ICProgressPlotView:0x7fe600fbfb90
  |   |   |   +UIView:0x7fe60300d890
  |   |   |   |   *ICProgressPlotAnnotationView:0x7fe6030083c0
  |   |   |   |   |   +UIView:0x7fe60300ac00
  |   |   |   |   |   |   *UIView:0x7fe600ed66b0
  |   |   |   |   |   |   *UILabel:0x7fe60300a240'32.3'
  |   |   |   |   |   |   *UIImageView:0x7fe60300ade0
  |   |   |   |   |   |   *UILabel:0x7fe600ed6ac0'4.5'
  |   |   |   |   *UIView:0x7fe600fc4760
  |   |   |   |   |   *UILabel:0x7fe600fc48d0' '
  |   |   |   |   *UILabel:0x7fe600fc5490' '
  |   |   |   |   *CPTGraphHostingView:0x7fe600fc2280
  |   |   *_UILayoutGuide:0x7fe600edcb50
  |   |   *_UILayoutGuide:0x7fe600edd590
  
  Legend:
      * - is laid out with auto layout
      + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
      • - layout engine host
  </code></pre>