title: how to add subviews in a 'for' loop
body: <p>I'm simply trying to add a UIView for every object in an array without displaying more than 3 on screen but the views aren't next to each other. There is a big gap (one view width) between each view. Here's what I've got;</p>
  
  <pre><code>int numberOfUsersOnScreen;
  
  if (array.count &lt; 3) {
      numberOfViewsOnScreen = array.count;
  }else{
      numberOfUsersOnScreen = 3;
  }
  
  double width = (self.scrollView.frame.size.width/numberOfViewsOnScreen);
  CGRect r = CGRectMake(0, 0, width, 1200);
  [self.usersScrollView setContentSize:CGSizeMake(width*array.count, 0)];
  
  for (int i = 0; i &lt; users.count; i++) {  
         r.origin.x = width * i;
         UIView * view = [[UIView alloc] initFrame:r];
         [self.scrollView addSubview:view];
  }    
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/kajnA.png" alt="The Orange is the scrollView underneath"></p>