Sunday, 14 August 2016

How to change Screen with UIPageController in iOS.

Today we will learn how to change Screen with UIPage Controller in iOS.


1. Create a new Xcode Project (Lets say UIPageControlDemo).
2. Now go to StoryBoard and take one label and one PageControl object.

3. Make proper IBOutlet Connection and then go to Your ViewController.m and write the following code.

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *pageNoLabel;
@property (weak, nonatomic) IBOutlet UIPageControl *pageController;


@implementation ViewController
    NSTimer *timer;

- (void)viewDidLoad {
    [super viewDidLoad];
    _pageController.currentPage = 0;
    _pageController.numberOfPages = 11;
    timer = [NSTimer timerWithTimeInterval:2 target:self selector:@selector(onTick:) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    // Do any additional setup after loading the view, typically from a nib.

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

-(void)onTick:(NSTimer *)timer1 {
    if (_pageController.currentPage == 10) {
        [timer invalidate];
        _pageController.currentPage = _pageController.currentPage+1;
        _pageNoLabel.text = [NSString stringWithFormat:@"%ld",(long)_pageController.currentPage];


4. Now run the code and see the desired ouput.

  Do customize it according to your own need.  Please share your reviews and comments.
You can download the whole Source code from here.

 Enjoy Coding :)

No comments:

Post a Comment

Ads Inside Post

Blogger Widget