This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class PageItemController: UIViewController { | |
// MARK: - Variables | |
// *** | |
var itemIndex: Int = 0 | |
// *** | |
var imageName: String = "" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@interface ViewController () <UIPageViewControllerDataSource> | |
@property (nonatomic, strong) NSArray *contentImages; | |
@property (nonatomic, strong) UIPageViewController *pageViewController; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UIPageViewControllerDataSource { | |
// MARK: - Variables | |
private var pageViewController: UIPageViewController? | |
// Initialize it right away here | |
private let contentImages = ["nature_pic_1", | |
"nature_pic_2", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation ViewController | |
#pragma mark View Lifecycle | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[self createPageViewController]; | |
[self setupPageControl]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - View Lifecycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
createPageViewController() | |
setupPageControl() | |
} | |
private func createPageViewController() { | |
let pageController = self.storyboard!.instantiateViewControllerWithIdentifier("PageController") as! UIPageViewController |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark UIPageViewControllerDataSource | |
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController | |
{ | |
PageItemController *itemController = (PageItemController *)viewController; | |
if (itemController.itemIndex > 0) | |
{ | |
return [self itemControllerForIndex:itemController.itemIndex-1]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - UIPageViewControllerDataSource | |
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? { | |
let itemController = viewController as! PageItemController | |
if itemController.itemIndex > 0 { | |
return getItemController(itemController.itemIndex-1) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark Page Indicator | |
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController | |
{ | |
return [_contentImages count]; | |
} | |
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController | |
{ | |
return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Page Indicator | |
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { | |
return contentImages.count | |
} | |
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { | |
return 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIViewController *)currentController | |
{ | |
if ([self.pageViewController.viewControllers count]) | |
{ | |
return self.pageViewController.viewControllers[0]; | |
} | |
return nil; | |
} |