Manually
- Add
HHPageView.h
andHHPageView.m
to your Project. - You need to provide images for active and inactive state. You can use these inside the sample project.
- Read the usage.
- All set.
Common steps:
-
Import
HHPageView
in your class where you want to use. -
Bind your ViewController with this delegate:
HHPageViewDelegate
.
@interface ViewController () <HHPageViewDelegate>
@end
1. Add in Storyboard or XIB.
- Define IBOutlet
HHPageView *pageView
. - You can add a
UIView
of the size you want. - Change the view type to
HHPageView
from the Identity Inspector > Custom Class. - Add below code to customzie
HHPageView
. - Done!
2. You can also add HHPageView
programmatically.
//Create HHPageView Instance with initial frame.
HHPageView *pageView = [[HHPageView alloc] initWithFrame:CGRectMake(0, 0, 160, 32)];
[self.view addSubview:pageView];
//Set delegate to the pageView object. To handle page changes event.
[pageView setDelegate:self];
//Set Base View.
//Note: You don't need to set baseScrollView if there's only one HHPageView per view controller.
[pageView setBaseScrollView:scrollView];
//Set Images for Active and Inactive state.
[pageView setImageActiveState:[UIImage imageNamed:@"selected.png"] InActiveState:[UIImage imageNamed:@"unselected.png"]];
//Tell HHPageView, the number of pages you want to show.
[pageView setNumberOfPages:totalPages];
//Set HHPageView Type: Horizontal or Vertical.
[pageControllerVertical setHHPageViewType:HHPageViewVerticalType];
//Tell HHPageView to show page from this page index.
[pageView setCurrentPage:3];
//Show when you ready!
[pageView load];
3. Handling Page Change Event
- (void) HHPageView:(HHPageView *)pageView currentIndex:(NSInteger)currentIndex {
[scrollView setContentOffset:CGPointMake(currentIndex * scrollView.frame.size.width, 0) animated:YES];
}
4. You should also implement UIScrollView Delegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scroll {
//If its not dragging
if(!scroll.isDragging) {
if(scroll.tag == HORIZONTAL_SCROLLVIEW_TAG) {
//for HHPageView horizontal
NSInteger pageWidth = scroll.frame.size.width;
NSInteger page = (floor((scroll.contentOffset.x - pageWidth / 2) / pageWidth) + 1) + 1;
[pageController updateStateForPageNumber:page];
} else {
//for HHPageView vertical
NSInteger pageHeight = scroll.frame.size.height;
NSInteger page = (floor((scroll.contentOffset.y - pageHeight / 2) / pageHeight) + 1) + 1;
[pageControllerVertical updateStateForPageNumber:page];
}
}
}
- A replacement of UIPageControl in iOS.
- Add either Horizontally or Vertically.
- Customization & Dynamic.
- Easy to setup and use.
- Customization options
- Swift Support
You can watch to HHPageView to see continuous updates. Stay tuned.
Have an idea for improvements of this class? Please open an issue.
You can shoot me an email to contact.
The MIT License (MIT)
Read the LICENSE file for details.