UIScrollView paging with buttons

i was wondering how you create a paging UIScrollView with buttons as the objects?

So far i have figured out to make a similar UIScrollView with images instead which looks like this:

    - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSArray *pictures = [NSArray arrayWithObjects: [UIImage imageNamed:@"nr1"], [UIImage imageNamed:@"nr2"], nil];


    for (int i = 0; i < pictures.count; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
        subview.image = [pictures objectAtIndex:i];
        [self.scrollView addSubview:subview];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * pictures.count, self.scrollView.frame.size.height);

}

Any tutorials would be appreciated :)

Answers


You will just add buttons instead of images

Replace this

UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [pictures objectAtIndex:i];
[self.scrollView addSubview:subview];

With

UIButton *subview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
subview.frame = frame;
[subview setTitle:@"Test" forState:UIControlStateNormal];
[self.scrollView addSubview:subview];

Need Your Help

Apache redirect when users home directory is completely empty

apache redirect directory hide

I work for an ISP and I have a server with thousands of users 10MB of free storage. They get this free storage with every e-mail account they have with us. An example of a users storage address: ht...