"Cocoanetics" is right. try this code.
uiScollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 360, 340)];
view.scrollEnabled = YES;
view.pagingEnabled=YES;
int y=20;
for (int i=0; i
UIButton *btn=[UIButton buttonWithType:UIButtonTyperoundRect];
[btn setTitle:[NSString stringwithFormate:@"%d",i] forState:UIControlStateNormal];
int x=0;
if (i%2==0) {
x=20;
}
else{
x=190;
}
[btn setFrame:CGRectMake(x, y,170*0.8,170*0.8)];
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
if (i%2==1) {
y=y+170;
}
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
btn.tag=i;
[view addSubview:btn];
}
[view setContentSize:CGSizeMake(360, y+150)];
[view scrollRectToVisible:CGRectMake(0, 0, 360, 340) animated:YES];
view.scrollEnabled=TRUE;
self.view = view;
self.view.backgroundColor = [UIColor clearColor];
[view release];
this works for me.