Search code examples
iosobjective-cuibuttonuipagecontrol

Add UIButton below UIPageIndicator


I'm building the tutorial section of an iOS app. I have three pages in the tutorial, and I've correctly set up the UIPageIndicators for each page. What I need is to put a UIButton below the UIPageIndicators and an image at the background. I have attached the design image also so that you understand what I mean.image description

Any ideas about that?

Thank you in advance!


Solution

  • i have implement same thing in my project and it's working fine for me.
    
    controller.h---->   
    
     @interface FastTickIntroScreen : UIViewController<UIScrollViewDelegate>
        {
            IBOutlet UIButton *btnStartMessgaing;
            IBOutlet UIScrollView *scrViewForIntro;
            IBOutlet UIPageControl *pageControl;
    
            NSMutableArray *arrImages;
    
            NSInteger pos;
            NSInteger posScr;
    
    
            //    IBOutlet UIPageControl *pageControl;
    
    
        }
        - (IBAction)btnStartMessgaingTapped:(id)sender;
    
    
        controller.m---->
    
    @implementation FastTickIntroScreen
    {
        CGFloat lastContentOffset;
    }
    
    #pragma mark-
    #pragma mark- UIbuttion Action Method
    
    
    -(void)viewDidLoad{
    
        arrImages=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"1FastTick"],
                   [UIImage imageNamed:@"2Chat"],
                   [UIImage imageNamed:@"3Video"],
                   [UIImage imageNamed:@"4Nearby"],
                   [UIImage imageNamed:@"5Discover"], nil];
    
        NSArray *arrTitle=[NSArray arrayWithObjects:@"",@"Real time texting",@"Instant video messaging",@"Nearby",@"Discover", nil];
    
        pos=0;
    
        posScr=0;
        scrViewForIntro.pagingEnabled = YES;
        scrViewForIntro.showsHorizontalScrollIndicator = NO;
        scrViewForIntro.showsVerticalScrollIndicator = NO;
        [scrViewForIntro setDelegate:self];
        scrViewForIntro.contentSize=CGSizeMake(self.view.frame.size.width*arrImages.count, 50);
    
        UILabel *lbl;
        UIImageView*imgViewForIntro;
    
        for (int i=0; i<arrImages.count; i++) {
    
            imgViewForIntro=[[UIImageView alloc]initWithFrame:CGRectMake(pos, 0, self.view.frame.size.width,
                                                                         self.view.frame.size.height)];
            [imgViewForIntro setImage:[arrImages objectAtIndex:i]];
            [scrViewForIntro addSubview:imgViewForIntro];
    
            lbl = [[UILabel alloc]initWithFrame:CGRectMake(pos, self.view.frame.size.height-130, self.view.frame.size.width,
                                                           30)];
            [lbl setText:[arrTitle objectAtIndex:i]];
            [lbl setTextAlignment:NSTextAlignmentCenter];
            [lbl setTextColor:[UIColor blackColor]];
            [lbl setFont:KSetFont(kDefaultFontName, 20)];
            [lbl setBackgroundColor:CLEARCOLOUR];
            [scrViewForIntro addSubview:lbl];
    
            pos = pos+self.view.frame.size.width;
            imgViewForIntro.tag=i;
        }
    
        pageControl.pageIndicatorTintColor = [UIColor grayColor];
        pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
        pageControl.numberOfPages = 5;
    }
    
    -(void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:YES];
        [self.navigationController.navigationBar setHidden:YES];
    }
    
    - (IBAction)btnStartMessgaingTapped:(id)sender {
    
    //    Congratulations *objScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"Congratulations"];
    //    [self.navigationController pushViewController:objScreen animated:YES];
    
        if(posScr<arrImages.count){
            posScr +=1;
            [scrViewForIntro scrollRectToVisible:CGRectMake(posScr*scrViewForIntro.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
            NSLog(@"Position: %li",(long)posScr);
            NSInteger pageNumber = roundf(scrViewForIntro.contentOffset.x / (scrViewForIntro.frame.size.width));
            pageControl.currentPage = pageNumber+=1;
    
            if (pageNumber == 5){
                TermsAndCondScreen *objScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"TermsAndCondScreen"];
                [self.navigationController pushViewController:objScreen animated:YES];
                posScr--;
            }
        }
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (lastContentOffset > scrollView.contentOffset.x)
        {
            CGFloat width = scrollView.frame.size.width;
            NSInteger page = (scrollView.contentOffset.x + (0.5f * width)) / width;
            posScr=page;
        }
        else if (lastContentOffset < scrollView.contentOffset.x)
        {
            CGFloat width = scrollView.frame.size.width;
            NSInteger page = (scrollView.contentOffset.x + (0.5f * width)) / width;
            posScr=page;
        }
        lastContentOffset = scrollView.contentOffset.x;
    
    }
    
    - (IBAction)changePage:(id)sender {
        CGFloat x = pageControl.currentPage * scrViewForIntro.frame.size.width;
        [scrViewForIntro setContentOffset:CGPointMake(x, 0) animated:YES];
    }
    
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView  {
        NSInteger pageNumber = roundf(scrViewForIntro.contentOffset.x / (scrollView.frame.size.width));
        pageControl.currentPage = pageNumber;
    }
    
    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    
    
    @end