0
我試圖加載多個UIViews
到UIScrollView
動態 - 就像facebook上的帖子。但我不太明白你如何動態地定位UIViews
。有人可以提供一些建議嗎?動態加載多個UIViews到UIScrollView
我試圖加載多個UIViews
到UIScrollView
動態 - 就像facebook上的帖子。但我不太明白你如何動態地定位UIViews
。有人可以提供一些建議嗎?動態加載多個UIViews到UIScrollView
我在網上找到了一個循環方法。想要感謝源,但我忘了我從哪裏得到它:
- (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];
}
}
任何原因你不想使用'UITableView'? – n00bProgrammer