title: Creating UIScrollView Programmatically
body: <p>I am trying to create a UIScrollView programatically. I set a property and synthesize it.</p>
  
  <pre><code>@property (weak, nonatomic) IBOutlet UIScrollView *topScrollView;
  @synthesize topScrollView;
  </code></pre>
  
  <p>I then have a method that does this. </p>
  
  <pre><code>[topScrollView setFrame:CGRectMake(320, 0, 320, 65)];
  [topScrollView setContentSize:CGSizeMake(500, 100)];
  [topScrollView setBackgroundColor:[UIColor greenColor]];
  [topScrollView setScrollEnabled:YES];
  [topScrollView setShowsHorizontalScrollIndicator:YES];
  [topScrollView setShowsVerticalScrollIndicator:NO];
  [[self view] addSubview:topScrollView]; 
  </code></pre>
  
  <p>I put this in viewDidLoad.
  This does not create the scroll view. I think it is because the scroll view has not been initialized. I can do the allocation and initialization in the above method but then when I want to use it in another method it wont work. I looked at <a href="https://stackoverflow.com/questions/10540936/programmatically-added-uiscrollview-used-in-multiple-methods?answertab=oldest#tab-top">Programmatically added UIScrollView used in multiple methods</a> but did not help too much. There is probably a simple solution that I am not aware of. What can I do to programmatically create this scroll view and be able to use it in another method(mainly to conduct animations with it).</p>
  
  <p>Thanks,</p>
  
  <p>Ivan</p>