在 UIPageIndicator 下面添加 UIButton

Add UIButton below UIPageIndicator

我正在构建 iOS 应用的教程部分。我在教程中有三个页面,我已经为每个页面正确设置了 UIPageIndicators。 我需要的是在 UIPageIndicators 下方放置一个 UIButton 并在背景中放置一个图像。我也附上了设计图片,以便您理解我的意思。

对此有什么想法吗?

提前致谢!

您遇到了什么问题?

您可以使用自定义页面控制器并向其添加一些约束。这样,您将对项目有更多的控制权。

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