123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- //
- // ViewController.m
- //
- // Copyright (c) 2013-2017 Evgeny Aleksandrov. License: MIT.
- #import <EAIntroView/EAIntroView.h>
- #import <SMPageControl/SMPageControl.h>
- #import "ViewController.h"
- static NSString * const sampleDescription1 = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
- static NSString * const sampleDescription2 = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore.";
- static NSString * const sampleDescription3 = @"Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.";
- static NSString * const sampleDescription4 = @"Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit.";
- @interface ViewController () <EAIntroDelegate> {
- UIView *rootView;
- EAIntroView *_intro;
- }
- @end
- @implementation ViewController
- #pragma mark - View lifecycle
- - (void)viewDidLoad {
- [super viewDidLoad];
- // using self.navigationController.view - to display EAIntroView above navigation bar
- rootView = self.navigationController.view;
- }
- #pragma mark - Demo
- - (void)showIntroWithCrossDissolve {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.desc = sampleDescription1;
- page1.bgImage = [UIImage imageNamed:@"bg1"];
- page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- EAIntroPage *page2 = [EAIntroPage page];
- page2.title = @"This is page 2";
- page2.desc = sampleDescription2;
- page2.bgImage = [UIImage imageNamed:@"bg2"];
- page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.desc = sampleDescription3;
- page3.bgImage = [UIImage imageNamed:@"bg3"];
- page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.desc = sampleDescription4;
- page4.bgImage = [UIImage imageNamed:@"bg4"];
- page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
- intro.skipButtonAlignment = EAViewAlignmentCenter;
- intro.skipButtonY = 80.f;
- intro.pageControlY = 42.f;
- [intro setDelegate:self];
- [intro showInView:rootView animateDuration:0.3];
- }
- - (void)showIntroWithFixedTitleView {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.desc = sampleDescription1;
- EAIntroPage *page2 = [EAIntroPage page];
- page2.title = @"This is page 2";
- page2.desc = sampleDescription2;
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.desc = sampleDescription3;
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.desc = sampleDescription4;
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
- [intro setDelegate:self];
- UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- intro.titleView = titleView;
- intro.titleViewY = 90;
- intro.backgroundColor = [UIColor colorWithRed:0.f green:0.49f blue:0.96f alpha:1.f]; //iOS7 dark blue
- [intro showInView:rootView animateDuration:0.3];
- }
- - (void)showIntroWithCustomPages {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.desc = sampleDescription1;
- page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- EAIntroPage *page2 = [EAIntroPage page];
- page2.title = @"This is page 2";
- page2.titlePositionY = self.view.bounds.size.height/2 - 10;
- page2.desc = sampleDescription2;
- page2.descPositionY = self.view.bounds.size.height/2 - 50;
- page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
- page2.titleIconPositionY = 70;
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.titleFont = [UIFont fontWithName:@"Georgia-BoldItalic" size:20];
- page3.titlePositionY = 220;
- page3.desc = sampleDescription2;
- page3.descFont = [UIFont fontWithName:@"Georgia-Italic" size:18];
- page3.descPositionY = 200;
- page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
- page3.titleIconPositionY = 100;
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.desc = sampleDescription4;
- page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
- intro.bgImage = [UIImage imageNamed:@"bg2"];
- intro.pageControlY = 250.f;
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [btn setFrame:CGRectMake(0, 0, 230, 40)];
- [btn setTitle:@"SKIP NOW" forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- btn.layer.borderWidth = 2.f;
- btn.layer.cornerRadius = 10;
- btn.layer.borderColor = [[UIColor whiteColor] CGColor];
- intro.skipButton = btn;
- intro.skipButtonY = 60.f;
- intro.skipButtonAlignment = EAViewAlignmentCenter;
- [intro setDelegate:self];
- [intro showInView:rootView animateDuration:0.3];
- }
- - (void)showIntroWithCustomView {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.desc = sampleDescription1;
- page1.bgImage = [UIImage imageNamed:@"bg1"];
- page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- UIView *viewForPage2 = [[UIView alloc] initWithFrame:rootView.bounds];
- UILabel *labelForPage2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, rootView.bounds.size.width, 30)];
- labelForPage2.text = @"Some custom view";
- labelForPage2.font = [UIFont systemFontOfSize:32];
- labelForPage2.textColor = [UIColor whiteColor];
- labelForPage2.backgroundColor = [UIColor clearColor];
- labelForPage2.transform = CGAffineTransformMakeRotation(M_PI_2*3);
- [viewForPage2 addSubview:labelForPage2];
- EAIntroPage *page2 = [EAIntroPage pageWithCustomView:viewForPage2];
- page2.bgImage = [UIImage imageNamed:@"bg2"];
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.desc = sampleDescription3;
- page3.bgImage = [UIImage imageNamed:@"bg3"];
- page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.desc = sampleDescription4;
- page4.bgImage = [UIImage imageNamed:@"bg4"];
- page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
- [intro.skipButton setTitle:@"Skip now" forState:UIControlStateNormal];
- [intro setDelegate:self];
- intro.tapToNext = YES;
- [intro showInView:rootView animateDuration:0.3];
- }
- - (void)showIntroWithCustomViewFromNib {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.desc = sampleDescription1;
- page1.bgImage = [UIImage imageNamed:@"bg1"];
- page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- EAIntroPage *page2 = [EAIntroPage pageWithCustomViewFromNibNamed:@"IntroPage"];
- page2.bgImage = [UIImage imageNamed:@"bg2"];
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.desc = sampleDescription3;
- page3.bgImage = [UIImage imageNamed:@"bg3"];
- page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.desc = sampleDescription4;
- page4.bgImage = [UIImage imageNamed:@"bg4"];
- page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
- [intro setDelegate:self];
- UISwitch *switchControl = (UISwitch *)[page2.pageView viewWithTag:1];
- if(switchControl) {
- [switchControl addTarget:self action:@selector(switchFlip:) forControlEvents:UIControlEventValueChanged];
- }
- [intro showInView:rootView animateDuration:0.3];
- _intro = intro;
- }
- - (void)showIntroWithSeparatePagesInitAndPageCallback {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.desc = sampleDescription1;
- page1.bgImage = [UIImage imageNamed:@"bg1"];
- page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- EAIntroPage *page2 = [EAIntroPage page];
- page2.title = @"This is page 2";
- page2.desc = sampleDescription2;
- page2.bgImage = [UIImage imageNamed:@"bg2"];
- page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
- page2.onPageDidAppear = ^{
- NSLog(@"Page 2 did appear block");
- };
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.desc = sampleDescription3;
- page3.bgImage = [UIImage imageNamed:@"bg3"];
- page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.desc = sampleDescription4;
- page4.bgImage = [UIImage imageNamed:@"bg4"];
- page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds];
- [intro setDelegate:self];
- // show skipButton only on 3rd page + animation
- intro.skipButton.alpha = 0.f;
- intro.skipButton.enabled = NO;
- page3.onPageDidAppear = ^{
- intro.skipButton.enabled = YES;
- [UIView animateWithDuration:0.3f animations:^{
- intro.skipButton.alpha = 1.f;
- }];
- };
- page3.onPageDidDisappear = ^{
- intro.skipButton.enabled = NO;
- [UIView animateWithDuration:0.3f animations:^{
- intro.skipButton.alpha = 0.f;
- }];
- };
- [intro setPages:@[page1,page2,page3,page4]];
- [intro showInView:rootView animateDuration:0.3];
- }
- - (void)showCustomIntro {
- EAIntroPage *page1 = [EAIntroPage page];
- page1.title = @"Hello world";
- page1.titlePositionY = 240;
- page1.desc = sampleDescription1;
- page1.descPositionY = 220;
- page1.bgImage = [UIImage imageNamed:@"bg1"];
- page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
- page1.titleIconPositionY = 100;
- page1.showTitleView = NO;
- EAIntroPage *page2 = [EAIntroPage page];
- page2.title = @"This is page 2";
- page2.titlePositionY = 240;
- page2.desc = sampleDescription2;
- page2.descPositionY = 220;
- page2.bgImage = [UIImage imageNamed:@"bg2"];
- page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon1"]];
- page2.titleIconPositionY = 260;
- EAIntroPage *page3 = [EAIntroPage page];
- page3.title = @"This is page 3";
- page3.titlePositionY = 240;
- page3.desc = sampleDescription3;
- page3.descPositionY = 220;
- page3.bgImage = [UIImage imageNamed:@"bg3"];
- page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon2"]];
- page3.titleIconPositionY = 260;
- EAIntroPage *page4 = [EAIntroPage page];
- page4.title = @"This is page 4";
- page4.titlePositionY = 240;
- page4.desc = sampleDescription4;
- page4.descPositionY = 220;
- page4.bgImage = [UIImage imageNamed:@"bg4"];
- page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon3"]];
- page4.titleIconPositionY = 260;
- EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
- intro.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigLogo"]];
- intro.titleViewY = 120;
- intro.tapToNext = YES;
- [intro setDelegate:self];
- SMPageControl *pageControl = [[SMPageControl alloc] init];
- pageControl.pageIndicatorImage = [UIImage imageNamed:@"pageDot"];
- pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"selectedPageDot"];
- [pageControl sizeToFit];
- // This is a hack - not recommended for Swift, more information: https://github.com/ealeksandrov/EAIntroView/issues/161
- intro.pageControl = (UIPageControl *)pageControl;
- intro.pageControlY = 130.f;
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- [btn setBackgroundImage:[UIImage imageNamed:@"skipButton"] forState:UIControlStateNormal];
- [btn setFrame:CGRectMake(0, 0, 270, 50)];
- intro.skipButton = btn;
- intro.skipButtonY = 80.f;
- intro.skipButtonAlignment = EAViewAlignmentCenter;
- [intro showInView:rootView animateDuration:0.3];
- }
- #pragma mark - EAIntroView delegate
- - (void)introDidFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped {
- if(wasSkipped) {
- NSLog(@"Intro skipped");
- } else {
- NSLog(@"Intro finished");
- }
- }
- #pragma mark - Custom actions
- - (IBAction)switchFlip:(id)sender {
- UISwitch *switchControl = (UISwitch *) sender;
- NSLog(@"%@", switchControl.on ? @"On" : @"Off");
- // limit scrolling on one, currently visible page (can't go previous or next page)
- //[_intro setScrollingEnabled:switchControl.on];
- if(!switchControl.on) {
- // scroll no further selected page (can go previous pages, but not next)
- _intro.limitPageIndex = _intro.visiblePageIndex;
- } else {
- [_intro setScrollingEnabled:YES];
- }
- }
- #pragma mark - UITableView delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- // all settings are basic, pages with custom packgrounds, title image on each page
- [self showIntroWithCrossDissolve];
- } else if (indexPath.row == 1) {
- // all settings are basic, introview with colored background, fixed title image
- [self showIntroWithFixedTitleView];
- } else if (indexPath.row == 2) {
- // basic pages with custom settings
- [self showIntroWithCustomPages];
- } else if (indexPath.row == 3) {
- // using page with custom view
- [self showIntroWithCustomView];
- } else if (indexPath.row == 4) {
- // using page with custom view from nib
- [self showIntroWithCustomViewFromNib];
- } else if (indexPath.row == 5) {
- // pages separate init and using block callback in one of pages
- [self showIntroWithSeparatePagesInitAndPageCallback];
- } else if (indexPath.row == 6) {
- // show custom intro
- [self showCustomIntro];
- }
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- @end
|