Did you ever want to implement a simple UIPageViewController
and realized that you had to do it all by code?
With BMPageViewController
you will be able to design each page from a single storyboard!
First you must create a subclass of BMPageViewController
and override -pageIdentifiers
. Example:
- (NSArray *)pageIdentifiers {
return @[@"page1", @"page2"];
}
Then you have to create a storyboard, add a UIPageViewController
object and change its class to BMPageViewController
.
Then you can add the controllers, setting their Storyboard ID
s to what you returned in pageIdentifiers
.
Each of them must be a class that conforms to BMPageViewControllerChild
(if you don't need to add any extra functionality to it you can use BMPageViewControllerPage
).
When your controller is instantiated, it will use these controllers to create each page.
Make sure you also check out the sample project in this repo.
If you need all your pages to look the same, but providing different data, you can create a single page in the storyboard and return it as many times as you need:
- (NSArray *)pageIdentifiers {
return @[@"page1", @"page1", @"page1"];
}
Then in your BMPageViewController
subclass you can override this method to configure each page:
- (void)setUpViewController:(MyCustomControllerPage *)page
atIndex:(NSInteger)index {
[super setUpViewController:page atIndex:index];
page.customData = [self dataForPageAtIndex:index];
}
Setting the initial page when BMPageViewController is loaded:
- (void) viewDidLoad {
self.currentPage = 3;
[self viewDidLoad];
}
Changing page programatically from BMViewControllerPages:
- (void) buttonClicked {
//self.parentViewController is a BMPageViewController subclass
[self.parentViewController changePage: 2];
}
if the current page is page 3 and we change the page above, the code will do the job and pick the correct direction of navigation.
- Using Cocoapods:
Just add this line to your Podfile
:
pod 'BMPageViewController', '~> 1.0.0'
- Manually:
Simply add the files under Source to your project.
- Requires ARC. If you want to use it in a project without ARC, mark the implementation files with the linker flag
-fobjc-arc
. - Supports iOS iOS6+.
BMPageViewController
is mainly based on MSPageViewController with some additions on paging support.
BMPageViewController
is available under the MIT license. See the LICENSE file for more info.