2012-08-31 25 views

回答

0

我在網上找到了一個循環方法。想要感謝源,但我忘了我從哪裏得到它:

- (void)constructPosts:(NSArray*)listOfItems 
{ 
    [scrollView setContentSize:CGSizeMake(self.view.frame.size.width, scrollView.frame.size.height*[listOfItems count])]; 
    CGRect frame = CGRectMake(10, 10, 300, 200); 
    for (int i = 0; i < [listOfItems count]; i++) 
    { 
     UIView *aView = [[UIView alloc] init]; 
     UILabel *test = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 100, 20)]; 
     [test setUserInteractionEnabled:YES]; 
     test.text = [NSString stringWithFormat:@"%@",[listOfItems objectAtIndex:i]]; 
     NSLog(@"setting up gestures"); 



     [aView addSubview:test]; 


     [aView setBackgroundColor:[UIColor grayColor]]; 
     frame.origin.y=((frame.size.width+5)*i+5 + (i/3) * 5); 
     aView.frame = frame; 
     [scrollView addSubview:aView]; 
    } 

}