daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 2nd, 2014 315 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //      "PageContentViewController.h"   //
  2.  
  3.  
  4. #import <UIKit/UIKit.h>
  5.  
  6. @interface PageContentViewController : UIViewController
  7. @property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
  8. @property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
  9. @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
  10.  
  11. @property NSUInteger pageIndex;
  12. @property NSString *titleText;
  13. @property NSString *imageFile;
  14.  
  15. @end
  16.  
  17. //      "PageContentViewController.m"   //
  18.  
  19. #import "PageContentViewController.h"
  20.  
  21. @interface PageContentViewController ()
  22.  
  23. @end
  24.  
  25. @implementation PageContentViewController
  26.  
  27. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  28. {
  29.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  30.     if (self) {
  31.         // Custom initialization
  32.     }
  33.     return self;
  34. }
  35.  
  36. - (void)viewDidLoad
  37. {
  38.     [super viewDidLoad];
  39.         // Do any additional setup after loading the view.
  40.        
  41.         self.pageControl.currentPage = self.pageIndex;
  42.        
  43.         self.backgroundImageView.image = [UIImage imageNamed:self.imageFile];
  44.     self.titleLabel.text = self.titleText;
  45. }
  46.  
  47. -(IBAction)dismiss:(id)sender
  48. {
  49.         // connected to Tap Gesture Recognizer so pageview can be dismissed on last page
  50.         NSUInteger index = _pageIndex;
  51.        
  52.         if (index == 4){
  53.                 [self dismissViewControllerAnimated:YES completion:nil];
  54.         }
  55. }
  56.  
  57. - (void)didReceiveMemoryWarning
  58. {
  59.     [super didReceiveMemoryWarning];
  60.     // Dispose of any resources that can be recreated.
  61. }
  62.  
  63. @end
  64.  
  65. //      "ViewController.m"      //
  66.  
  67. #import "ViewController.h"
  68.  
  69. @interface ViewController ()
  70.  
  71. @end
  72.  
  73. @implementation ViewController
  74.  
  75. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  76. {
  77.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  78.     if (self) {
  79.         // Custom initialization
  80.     }
  81.     return self;
  82. }
  83.  
  84. - (void)viewDidLoad
  85. {
  86.     [super viewDidLoad];
  87.         // Do any additional setup after loading the view.
  88.        
  89.         // Create the data model
  90.         _pageTitles = @[@"1", @"2", @"3", @"4", @"5"];
  91.     _pageImages = @[@"page1.png", @"page2.png", @"page3.png", @"page4.png", @"page5.png"];
  92.        
  93.     // Create page view controller
  94.     self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
  95.     self.pageViewController.dataSource = self;
  96.        
  97.     PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
  98.     NSArray *viewControllers = @[startingViewController];
  99.     [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  100.        
  101.     // Change the size of page view controller
  102.     self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  103.        
  104.     [self addChildViewController:_pageViewController];
  105.     [self.view addSubview:_pageViewController.view];
  106.     [self.pageViewController didMoveToParentViewController:self];
  107. }
  108.  
  109. - (void)didReceiveMemoryWarning
  110. {
  111.     [super didReceiveMemoryWarning];
  112.     // Dispose of any resources that can be recreated.
  113. }
  114.  
  115. - (IBAction)startWalkthrough:(id)sender {
  116.         // I don't use a restart button, so not implemented
  117. }
  118.  
  119. - (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index
  120. {
  121.     if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {
  122.         return nil;
  123.     }
  124.        
  125.     // Create a new view controller and pass suitable data.
  126.     PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"];
  127.     pageContentViewController.imageFile = self.pageImages[index];
  128.     pageContentViewController.titleText = self.pageTitles[index];
  129.     pageContentViewController.pageIndex = index;
  130.        
  131.     return pageContentViewController;
  132. }
  133.  
  134. #pragma mark - Page View Controller Data Source
  135.  
  136. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
  137. {
  138.     NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
  139.        
  140.     if ((index == 0) || (index == NSNotFound)) {
  141.         return nil;
  142.     }
  143.        
  144.     index--;
  145.     return [self viewControllerAtIndex:index];
  146. }
  147.  
  148. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
  149. {
  150.     NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
  151.        
  152.     if (index == NSNotFound) {
  153.         return nil;
  154.     }
  155.        
  156.     index++;
  157.     if (index == [self.pageTitles count]) {
  158.         return nil;
  159.     }
  160.     return [self viewControllerAtIndex:index];
  161. }
  162.  
  163. // commented out, since not necessary. set through interface builder
  164.  
  165. //- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
  166. //{
  167. //      return [self.pageTitles count];
  168. //}
  169. //
  170. //- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
  171. //{
  172. //      return 0;
  173. //}
  174.  
  175. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top