I'm trying to load mutiple UIViews
into UIScrollView
dynamically - just like posts on facebook. But I don't quite understand how you position the UIViews
dynamically one after another. Can someone provide me some advice?
问问题
149 次
1 回答
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];
}
}
于 2012-09-01T12:15:28.827 回答