关于APP引导页的简单制作

本文介绍了一个iOS应用中引导页的实现方法,通过UIScrollView展示多张图片,并为每一页添加了点击进入按钮。文章还展示了如何使用单例模式来管理引导页控制器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.h文件

#import <UIKit/UIKit.h>


@protocol GuideViewControllerDelegate;

@interface GuideViewController : UIViewController

@property(nonatomic,assign)id<GuideViewControllerDelegate>delegate;

// 创建单利类

+ (instancetype)shareGuideVC;

// 初始化引导页

- (void)initWithGuideView:(NSArray *)images;


@end

@protocol GuideViewControllerDelegate <NSObject>

-(void)click;

@end


.m 文件

#pragma mark 初始化引导页

-(void)initWithGuideView:(NSArray *)images

{

    UIScrollView * guideScrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];

    guideScrollview.pagingEnabled = YES;

    guideScrollview.showsVerticalScrollIndicator = NO;

    guideScrollview.showsHorizontalScrollIndicator = NO;

    guideScrollview.bounces = NO;

    for (int i = 0; i<images.count; i++) {

        [guideScrollview addSubview:({

            self.enterBtn = [UIButton buttonWithType:UIButtonTypeCustom];

            self.enterBtn.frame = CGRectMake(ScreenWidth * i, 0, ScreenWidth, ScreenHeight);

            [self.enterBtn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];;

            self.enterBtn;

        })];

        [self.enterBtn addSubview:({

            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

            [btn setTitle:@"点击进入" forState:UIControlStateNormal];

            btn.frame = CGRectMake(ScreenWidth * i, ScreenHeight - 60, 100, 40);

            btn.center = CGPointMake(ScreenWidth / 2, ScreenHeight - 60);

            btn.backgroundColor = [UIColor lightGrayColor];

            [btn addTarget:self action:@selector(clickEnter) forControlEvents:UIControlEventTouchUpInside];

            btn;

        })];

    }

    guideScrollview.contentSize = CGSizeMake(ScreenWidth * images.count, 0);

    [self.view addSubview:guideScrollview];

//    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, s_w / 2, 30)];

//    self.pageControl.center = CGPointMake(s_w / 2, s_h - 95);

//    [self.view addSubview:self.pageControl];

//    self.pageControl.numberOfPages = images.count;

+ (instancetype)shareGuideVC

{

    static GuideViewController *x = nil;

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        x = [[GuideViewController alloc] init];

    });

    return x;

}

- (void)clickEnter

{

    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(click)]) {

        [self.delegate click];

    }

}

#pragma mark - ScrollerView Delegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    //self.pageControl.currentPage = scrollView.contentOffset.x / s_w;

}

然后在appdelegate调用:

    self.window.rootViewController = [GuideViewController shareGuideVC];

    [[GuideViewController shareGuideVC] initWithGuideView:@[@"bg.png"]];

    [GuideViewController shareGuideVC].delegate = self;

//实现代理协议 

#pragma mark 点击直接进入

-(void)click

{

    [self makeTabbar];

}

1:控制引导页的出现逻辑根据需求觉得。

2:引导页加载网络图片还是本地图片自己修改。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值