你可以这样使用:使用 MyScrollView.pagingEnabled=YES。
int PageNum=0;
if(TotalButtons%3 >0)
{
pageNum=TotalButtons/3;
pageNum++;
}
else{
PageNum=TotalButtons/3;
}
[MyScrollView setContentSize:CGSizeMake(320*pageNum, MyScrollView.frame.size.height)];
根据您想要在滚动视图上的宽度和间距添加按钮。
编辑:
int x=56;
int y=60;
for(int i=1;i<= 60;i++)
{
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(x, y, 200, 120);
button.tag=i;
// [button setTitle:[NSString stringWithFormat:@"Video-%d",i+1] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"220x200.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(ButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[VideoStoreScroll addSubview:button];
if(i%6==0)
{
count++;
x=(count-1)*VideoStoreScroll.frame.size.width+56;
y=50;
}
else
{
if(i%3==0)
{
x=(count-1)*VideoStoreScroll.frame.size.width+56;
y=y+190;
}
else
{
x=x+256;
}
}
}
VideoStoreScroll.contentSize=CGSizeMake(x-56, 480);
VideoStoreScroll.contentOffset=CGPointMake(0, 0);
在这里,我在每页滚动时水平使用六个按钮。您可以在此之后工作三个。