引导页
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#import "NextViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.next = [[NextViewController alloc]init];
// 判断程序是否第一次打开
NSUserDefaults *TimeOfBootCount = [NSUserDefaults standardUserDefaults];
if (![TimeOfBootCount valueForKey:@"firstLaunch"])
{
[TimeOfBootCount setBool:YES forKey:@"firstLaunch"];
ViewController *v1 = [[ViewController alloc]init];
self.window.rootViewController = v1;
NSLog(@"第一次启动");
}
else
{
NextViewController *next1 = [[NextViewController alloc]init];
self.window.rootViewController = next1;
NSLog(@"不是第一次启动");
}
[self.window makeKeyAndVisible];
NSLog(@"启动成功");
return YES;
}
ViewController.m
#import "ViewController.h"
#import "NextViewController.h
"#import "AppDelegate.h"
@interface ViewController (){
// 创建滚动视图
UIScrollView *theScroll;
// 创建页码视图
UIPageControl *thePage;
// 创建图片的数组
NSArray *theArr;
// 创建整形类
NSInteger teg;
// 创建计时器
NSTimer *theTime;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 获取当前屏幕的宽
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
// 初始化滚动视图
theScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
float X = 0.0;
for (int i =0; i<4; i++)
{
// 创建图片视图
UIImageView *theImg = [[UIImageView alloc]initWithFrame:CGRectMake(X, 0, width, height)];
// 将图片添加带数组中
theArr = @[[UIImage imageNamed:@"IMG1"],[UIImage imageNamed:@"IMG2"],[UIImage imageNamed:@"IMG3"],[UIImage imageNamed:@"IMG4"]];
// 将图片与数据联系
theImg.image = theArr[i];
// 将图片添加到滚动视图上
[theScroll addSubview:theImg];
// X依次递增
X += width;
}
// 设置滚动视图内容大小
theScroll.contentSize = CGSizeMake(width *4, height);
// 设置是否按页滚动
theScroll.pagingEnabled = YES;
// 隐藏滚动条
theScroll.showsHorizontalScrollIndicator = NO;
// 设置代理
theScroll.delegate = self;
// 创建页码
thePage = [[UIPageControl alloc]initWithFrame:CGRectMake(width / 2-50, 570, 100, 30)];
// 清除页码的背景颜色
thePage.backgroundColor = [UIColor clearColor];
// 设置当前页码的颜色
thePage.currentPageIndicatorTintColor = [UIColor blackColor];
// 设置页码的颜色
thePage.pageIndicatorTintColor = [UIColor redColor];
// 设置页码的个数
thePage.numberOfPages = 4;
// 设置页码的起始页码
thePage.currentPage = 0;
// 添加到视图上
// 先添加滚动视图
[self.view addSubview:theScroll];
// 再添加页码视图
[self.view addSubview:thePage];
// 使用整形变量接受页码当前的页码
teg = thePage.currentPage;
// 创建定时器
theTime = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scroll) userInfo:nil repeats:YES];
}
// 定时器的方法
- (void)scroll
{
teg ++;
if (teg >= theArr.count)
{
teg = 0;
}
// 设置滚动视图的内容偏移量
[theScroll setContentOffset:CGPointMake(teg *self.view.frame.size.width, 0) animated:YES];
}
// 滚动视图的代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint point = theScroll.contentOffset;
thePage.currentPage = point.x/scrollView.frame.size.width;
// 创建按钮
UIButton *theBtn = [[UIButton alloc]init];
if (thePage.currentPage == 3)
{
[theTime setFireDate:[NSDate distantFuture]];
// 当滚动到最后一张图片的时候出现按钮
// 设置按钮位置 z
theBtn.frame = CGRectMake(230, 607, 100, 40);
// 设置按钮内容
[theBtn setTitle:@"立即登录" forState:UIControlStateNormal];
// 设置按钮背景颜色
theBtn.backgroundColor = [UIColor redColor];
// 设置按钮响应事件
[theBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
// 添加到视图上 B
[self.view addSubview:theBtn];
}
}
// 按钮方法
- (void)click
{
NextViewController *next = [[NextViewController alloc]init];
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.window.rootViewController = next;
}
NextViewController.m
TableView