.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:引导页加载网络图片还是本地图片自己修改。