title: Change width of custom UIControl and keep centered with Autolayout
body: <p>I have a problem with an UIControl and Autolayout. 
  I created a custom UIControl, then I add it with Interface Builder and then add the constraints. 
  The control is similar to UIPageControl and works like this, for every page, one dot is added and the width of the control changes. The problem is I don't know how to resize the UIControl programmatically and keep the control centered with Autolayout.</p>
  
  <p>I attached a picture where you see one of the problems, the size, particularly the width.
  Yellow part is centered, but dots are out of the box. </p>
  
  <p>Thank you!</p>
  
  <p><img src="https://i.stack.imgur.com/H87GO.png" alt="enter image description here"></p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here is the code when I update dots count:</p>
  
  <pre><code>- (void)reloadNumberOfPages:(NSUInteger)pages {
  
      // Remove previous images
      for (UIView *v in self.subviews) {
          [v removeFromSuperview];
      }
  
      // Change size
      CGFloat width = _dotSize.width * pages;
      CGPoint center = self.center;
  
      // Change size
      self.frame = ({
  
          CGRect frame = self.frame;
          frame.size.width = width;
          frame.size.height = _dotSize.height;
          frame;
  
      });
      self.center = center;
  
      // Add images
      CGFloat offSet = 0.0;
      for (int x = 0; x &lt; pages; x++) {
  
          // Image
          UIImageView *dot = [[UIImageView alloc] initWithImage:_dotOFF
                                               highlightedImage:_dotON];
          dot.frame = CGRectMake(offSet, 0.0, _dotSize.width, _dotSize.height);
          dot.center = CGPointMake(CGRectGetMidX(dot.frame), CGRectGetHeight(self.bounds) / 2.0);
          dot.tag = x;
          [self addSubview:dot];
  
          // Añadimos offSet
          offSet += CGRectGetWidth(dot.bounds);
  
      }
  
  }
  </code></pre>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I'm trying with "intrinsicContentSize" but it doesn't work</p>
  
  <pre><code>- (void)reloadNumberOfPages:(NSUInteger)pages {
  
      // Add images
      CGFloat offSet = 0.0;
      for (int x = 0; x &lt; pages; x++) {
  
          // Image
          UIImageView *dot = [[UIImageView alloc] initWithImage:_dotOFF
                                               highlightedImage:_dotON];
          dot.frame = CGRectMake(offSet, 0.0, _dotSize.width, _dotSize.height);
          dot.center = CGPointMake(CGRectGetMidX(dot.frame), CGRectGetHeight(self.bounds) / 2.0);
          dot.tag = x;
          [self addSubview:dot];
  
          // Añadimos offSet
          offSet += CGRectGetWidth(dot.bounds);
  
      }
  
      [self invalidateIntrinsicContentSize];
  
  }
  
  - (CGSize)intrinsicContentSize {
      return CGSizeMake(_dotSize.width * _numberOfPages, _dotSize.height);
  }
  </code></pre>