I am trying to use a UIPageControl with my UIScrollView. It seems that i’m doing something improperly cause the page is always set to one.
This is my ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView.delegate = self;
UIImageView *imgView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen1.png"]];
imgView1.frame = CGRectMake(0, 0, 320, 436);
[scrollView addSubview:imgView1];
UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen2.png"]];
imgView2.frame = CGRectMake(320, 0, 320, 436);
[scrollView addSubview:imgView2];
UIImageView *imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen3.png"]];
imgView3.frame = CGRectMake(640, 0, 320, 436);
[scrollView addSubview:imgView3];
scrollView.contentSize = CGSizeMake(960, 436);
pageControl = [[UIPageControl alloc] init];
[pageControl setNumberOfPages:3];
[pageControl setCurrentPage:0];
}
And here is my UIScrollView Delegate Method:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollViewx{
NSLog(@"%f",scrollView.contentOffset.x);
NSLog(@"%f",(scrollViewx.contentOffset.x / 320));
pageControl.currentPage = ((scrollViewx.contentOffset.x / 320));
}
And here is y .h file:
@interface TutorialViewController : UIViewController <UIScrollViewDelegate>
@property (nonatomic,strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic,strong) IBOutlet UIPageControl *pageControl;
@end
Does anyone have an idea why it doesn’t change? Of course i made sure my UIPageControl is connected to its instance.
Appreciate your help…
OK. the dot isn’t changing because you’ve created a new UIPageControl instead of using the one you set up in IB. Take out:
pageControl = [[UIPageControl alloc] init];