title: Programmatically position UIView before viewDidAppear
body: <p>I've got two UIViews. The first contains a variable number of UIButtons which might overflow into <code>two rows</code>. The second needs to be positioned below the first.</p>
  
  <p>I have read a lot of posts like this: <a href="https://stackoverflow.com/questions/4410011/how-to-position-a-uiview">How to position a UIView?</a> </p>
  
  <p>Unfortunately, these seem to only work if you call them in the <code>viewDidAppear:</code> method or later. This means that there is a short amount of time between when my views load and when my elements are correctly positioned.</p>
  
  <p>How can I elegantly solve this problem?</p>
  
  <p>Edit 1:
  Here is a simple method I am using the adjust view2 downwards</p>
  
  <pre><code>-(void)adjustView:(UIView *)view down:(int)down{
      CGRect frame = view.frame;
      frame.origin.y = frame.origin.y + down;
      view.frame = frame;
      }
  </code></pre>
  
  <p>Edit 2:
  This is something like how I am adding my buttons, resizing my first view, and calculating how far the next one needs to go down</p>
  
  <pre><code>- (void)addButtonsToView:(NSArray *)buttonStrings {
      //To correctly position
      float previousTagsWidth = 0.0;
      self.adjustDown = 0.0;
  
      for (NSString *str in buttonStrings) {      
          UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
          [button setTitle:str forState:(UIControlState)UIControlStateNormal];
  
          CGSize size = [str sizeWithFont:TAG_FONT];
          if (previousTagsWidth + size.width &gt; 300) {
              previousTagsWidth = 0;
              self.adjustDown += size.height+10;
              }
  
          button.frame = CGRectMake(previousTagsWidth, self.adjustDown, size.width+10, size.height+5);
          previousTagsWidth += size.width+20;
  
          [self.view1 addSubview:button];
          }
      CGRect frame = self.view1.frame;
      frame.size.height = frame.size.height+self.adjustDown;
      self.view1.frame = frame;
      }
  </code></pre>