Reputation: 513
This is what i have so far, I have a scroller and two buttons that i want to be on the scroller, but i cant get to the second button because it wont scroll around to it. I would greatly appreciate if anyone can see the error in my code.
UIScrollView *mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 65, 320, 4000)];
mainScroll.contentSize = CGSizeMake(320, 4000);
mainScroll.showsHorizontalScrollIndicator = YES;
[self.view addSubview:mainScroll];
[mainScroll setScrollEnabled:YES];
UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
action:@selector(goToCreateGameViewController)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(75, 10, 170, 60);
UIButton *anotherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[anotherButton addTarget:self
action:@selector(goFuckOffApple)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview: anotherButton];
anotherButton.frame = CGRectMake(75, 3000, 170, 60);
Upvotes: 0
Views: 421
Reputation: 43330
Well, besides the hilarious method names (goF**kOffApple, LOL), you are setting your scroll view's frame to the same size as it's content. Frame and content size are different animals. Try this:
UIScrollView *mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 65, 320, 395)];
mainScroll.contentSize = CGSizeMake(320, 4000);
mainScroll.showsVerticalScrollIndicator = YES;
[self.view addSubview:mainScroll];
[mainScroll setScrollEnabled:YES];
UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
action:@selector(goToCreateGameViewController)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(75, 10, 170, 60);
UIButton *anotherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[anotherButton addTarget:self
action:@selector(goFuckOffApple)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview: anotherButton];
anotherButton.frame = CGRectMake(75, 3000, 170, 60);
Upvotes: 1