How do I use UIPageControl with iCarousel?
I have several images inside icarousel. (about 20 images)
I want 5 images per page.
No problem with pixel positioning of an image or image.
How to use uipagecontrol WITHOUT ScrollView?
ex), capable of using some delegate methods, etc.
carousel.type = iCarouselTypeLinear;
carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 504, 1024, 164)];
carousel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"10004.png"]];
carousel.delegate = self;
carousel.dataSource = self;
[self.view addSubview:carousel];
[carousel reloadData];
[carousel release];
UIView *bandImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 668, 1024, 20)];
bandImageView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"10001.png"]];
[self.view addSubview:bandImageView]; // page dots in
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(434, 0, 150, 20);
pageControl.numberOfPages = 6;
pageControl.currentPage = 0;
[bandImageView addSubview:pageControl];
[pageControl release];
+3
source to share
1 answer
In the iCarousel delegate method, carouselCurrentItemIndexUpdated:
set
pageControl.currentPage = carousel.currentItemIndex / 5
Then bind the pageControl action to a method like the one below:
- (IBAction)updatePage:(UIPageControl *)pageControl
{
[carousel scrollToItemAtIndex:pageControl.currentPage * 5 aimated:YES];
}
If you are not using a nib file you can bind the action with
[pageControl addTarget:self action:@selector(updatePage:) forControlEvents:UIControlEventValueChanged];
Recommended to install pageControl.defersCurrentPageDisplay = YES;
to avoid flickering.
+10
source to share