Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tutorial SCreen
#import <UIKit/UIKit.h>
#import "TutorialScreenController.h"
@interface TutorialPopoverScreen : UIViewController
@property (assign, nonatomic) NSInteger index;
@property (strong, nonatomic) IBOutlet UILabel *screenNumber;
@property UIButton *button;
@property UIImageView *image;
@end
#import "TutorialPopoverScreen.h"
#import "AppDelegate.h"
@implementation TutorialPopoverScreen{
AppDelegate *sharedDelegate;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
-(instancetype)init{
self = [super init];
if(self){
self.view.backgroundColor = [UIColor whiteColor];
sharedDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[self setup];
}
return self;
}
-(void)setup{
_image = [CustomViews customImageViewNoBorder:@"placeHolder"];
[self.view addSubview:_image];
// Image
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_image attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0f]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_image attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0f]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_image attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_image attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]];
_button = [CustomViews buttonWithString:@"Get Started" options:@{@"font-name" : @"Helvetica-Bold", @"font-size" : @14, @"background-color" : [CustomScripts colorWithHexString:@"#a4ce39"], @"font-color" : [UIColor whiteColor]}];
_button.translatesAutoresizingMaskIntoConstraints = YES;
_button.titleLabel.numberOfLines = 2;
[CustomScripts addShadowToView:_button options:@{}];
[self.view addSubview:_button];
}
@end
#import "TutorialScreenController.h"
#import "TutorialPopoverScreen.h"
#import "AppDelegate.h"
#define NUMBEROFSLIDES 6
@implementation TutorialScreenController{
AppDelegate *sharedDelegate;
NSUInteger currentIndex;
}
-(instancetype)init{
self = [super init];
if(self){
sharedDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
TutorialPopoverScreen *initialViewController = [self viewControllerAtIndex:0];
currentIndex = 0;
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
[self setup];
}
-(void)cancelPopover:(UIButton*)sender{
[self dismissViewControllerAnimated:YES completion:nil];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@true forKey:@NSUSERFIRSTLOGIN];
[defaults synchronize];
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleDefault;
}
-(void)setup{
}
- (void)changePage:(UIButton*)sender {
if(currentIndex == 5){
[self cancelPopover:sender];
return;
}
currentIndex++;
TutorialPopoverScreen *viewController = [self viewControllerAtIndex:currentIndex];
if (viewController == nil) {
return;
}
[_pageController setViewControllers:@[viewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (TutorialPopoverScreen *)viewControllerAtIndex:(NSUInteger)index {
currentIndex = index;
TutorialPopoverScreen *childViewController = [[TutorialPopoverScreen alloc]init];
if(index == 0){
childViewController.button.tag = 0;
childViewController.button.frame = CGRectMake(self.view.frame.size.width/2-75*ESTIMATEDPHONEWIDTH, self.view.frame.size.height/2+(80-37.5)*ESTIMATEDPHONEHEIGHT,150*ESTIMATEDPHONEWIDTH, 75*ESTIMATEDPHONEHEIGHT);
childViewController.button.titleLabel.text = @"Get Started";
childViewController.image.image = [UIImage imageNamed:@"Mockup_New_To_App_Flow01"];
}else if(index == 1){
childViewController.button.tag = 1;
childViewController.button.frame = CGRectMake(self.view.frame.size.width/2-75*ESTIMATEDPHONEWIDTH, self.view.frame.size.height/2+(150-37.5)*ESTIMATEDPHONEHEIGHT,150 *ESTIMATEDPHONEWIDTH, 75*ESTIMATEDPHONEHEIGHT);
[childViewController.button setTitle:@"Next" forState:UIControlStateNormal];
childViewController.image.image = [UIImage imageNamed:@"Mockup_New_To_App_Flow02"];
}else if(index == 2){
childViewController.button.tag = 2;
childViewController.button.frame = CGRectMake(self.view.frame.size.width/2-75*ESTIMATEDPHONEWIDTH, self.view.frame.size.height/2+(240-32.5)*ESTIMATEDPHONEHEIGHT,150*ESTIMATEDPHONEWIDTH, 70*ESTIMATEDPHONEHEIGHT);
[childViewController.button setTitle:@"Next" forState:UIControlStateNormal];
childViewController.image.image = [UIImage imageNamed:@"Mockup_New_To_App_Flow03"];
}else if(index == 3){
childViewController.button.tag = 3;
childViewController.button.frame = CGRectMake(self.view.frame.size.width/2-75*ESTIMATEDPHONEWIDTH, self.view.frame.size.height/2+(252-32.5)*ESTIMATEDPHONEHEIGHT,150*ESTIMATEDPHONEWIDTH, 65*ESTIMATEDPHONEHEIGHT);
[childViewController.button setTitle:@"Next" forState:UIControlStateNormal];
childViewController.image.image = [UIImage imageNamed:@"Mockup_New_To_App_Flow04"];
}else if(index == 4){
childViewController.button.tag = 4;
childViewController.button.frame = CGRectMake(self.view.frame.size.width/2-70*ESTIMATEDPHONEWIDTH, self.view.frame.size.height/2-(135)*ESTIMATEDPHONEHEIGHT,140*ESTIMATEDPHONEWIDTH, 65*ESTIMATEDPHONEHEIGHT);
[childViewController.button setTitle:@"Next" forState:UIControlStateNormal];
childViewController.image.image = [UIImage imageNamed:@"Mockup_New_To_App_Flow05"];
}else if(index == 5){
childViewController.button.frame = CGRectMake(self.view.frame.size.width/2-65*ESTIMATEDPHONEWIDTH, self.view.frame.size.height/2+(110-32.5)*ESTIMATEDPHONEHEIGHT, 130*ESTIMATEDPHONEWIDTH, 65*ESTIMATEDPHONEHEIGHT);
[childViewController.button setTitle:@"Finish" forState:UIControlStateNormal];
childViewController.button.tag = 5;
childViewController.image.image = [UIImage imageNamed:@"Mockup_New_To_App_Flow06"];
}
childViewController.index = index;
[childViewController.button addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventTouchUpInside];
return childViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [(TutorialPopoverScreen *)viewController index];
if (index == 0) {
return nil;
}
// Decrease the index by 1 to return
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(TutorialPopoverScreen *)viewController index];
//Increase index by 1 to return, if index is 5 don't increase.
index++;
if (index == NUMBEROFSLIDES) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return NUMBEROFSLIDES;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return -1;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment