What you need to do is create a loop, create UIButtons . Settings buttons and add them as subzones on the UIScrollView . The code follows.
NSUInteger i; int xCoord=0; int yCoord=0; int buttonWidth=100; int buttonHeight=50; int buffer = 10; for (i = 1; i <= 100; i++) { UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]; aButton.frame = CGRectMake(xCoord, yCoord,buttonWidth,buttonHeight ); [aButton addTarget:self action:@selector(whatever:) forControlEvents:UIControlEventTouchUpInside]; [scrollView addSubview:aButton]; yCoord += buttonHeight + buffer; } [scrollView setContentSize:CGSizeMake(700, yCoord)];
Basically, I have variables for the X and Y coordinates here. When I move on to creating UIButtons , I create the appropriate CGRect structure to decide where to place the button in the UIScrollView . After adding this button to scrollView, change the X and Y values ββto the place where you want to place the next button.
In the end, be sure to set ContentSize to scroll so that it ContentSize scrolling.
PS: all this code is typed with your free hand, it may have small syntax errors, but the logic is solid.
source share