将多个UIView动态加载到UIScrollView

将多个UIView动态加载到UIScrollView,uiview,uiscrollview,Uiview,Uiscrollview,我正在尝试将多个UIViews动态加载到UIScrollView中,就像facebook上的帖子一样。但是我不太明白您是如何一个接一个地动态定位ui视图的。有人能给我一些建议吗?我在网上找到了一种循环方法。我想感谢消息来源,但我忘了是从哪里得到的: - (void)constructPosts:(NSArray*)listOfItems { [scrollView setContentSize:CGSizeMake(self.view.frame.size.width, scrollVi

我正在尝试将多个
UIViews
动态加载到
UIScrollView
中,就像facebook上的帖子一样。但是我不太明白您是如何一个接一个地动态定位
ui视图的。有人能给我一些建议吗?

我在网上找到了一种循环方法。我想感谢消息来源,但我忘了是从哪里得到的:

- (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];
    }

}
-(void)constructPosts:(NSArray*)项目列表
{
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width,scrollView.frame.size.height*[ListoItems count]);
CGRect frame=CGRectMake(10,10,300,200);
对于(int i=0;i<[listOfItems count];i++)
{
UIView*aView=[[UIView alloc]init];
UILabel*test=[[UILabel alloc]initWithFrame:CGRectMake(0,20,100,20)];
[测试集UserInteractionEnabled:是];
test.text=[NSString stringWithFormat:@“%@”,[ListoItems objectAtIndex:i]];
NSLog(“设置手势”);
[查看添加子视图:测试];
[aView setBackgroundColor:[UIColor grayColor]];
frame.origin.y=((frame.size.width+5)*i+5+(i/3)*5);
aView.frame=frame;
[滚动视图添加子视图:aView];
}
}

您不想使用
UITableView的任何原因