引导页是每个App都需要的,虽然它只在第一次打开App的时候才显示.下面我就讲一下怎么制作一个简单的引导页.
新建一个UIViewController,用来写引导页
在这个引导页的ViewController里,导入头文件
#import “AppDelegate.h"
然后就可以铺界面了,引导页有横滑和竖滑的,我这里做的是横滑的.
@interface LSStartViewController ()
@property (nonatomic, retain)NSMutableArray *pageArr;
@property (nonatomic, retain)UIScrollView *startScrollV;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.startScrollV = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
self.startScrollV.contentSize = CGSizeMake(WIDTH * 3, HEIGHT);
self.startScrollV.pagingEnabled = YES;
self.startScrollV.bounces = NO;
self.startScrollV.showsHorizontalScrollIndicator = NO;
//添加3张引导页图片
self.pageArr = [NSMutableArray arrayWithObjects:@"qidongye1.png",@"qidongye2.png",@"qidongye3.png", nil];
for (int i = 0; i < 3; i++) {
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[self.pageArr objectAtIndex:i]]];
img.frame = CGRectMake(0 + WIDTH * i, 0, WIDTH, HEIGHT);
[self.startScrollV addSubview:img];
[img release];
}
[self.view addSubview:self.startScrollV];
//在最后一张图片上添加按钮
UIButton *act = [UIButton buttonWithType:UIButtonTypeCustom];
[act setTitle:@"点击体验>>" forState:UIControlStateNormal];
[act addTarget:self action:@selector(btnAct:) forControlEvents:UIControlEventTouchUpInside];
act.frame = CGRectMake(WIDTH * 2, HEIGHT / 2, WIDTH, 50 * HEIGHT / 667);
[self.startScrollV addSubview:act];
[_startScrollV release];
}
//按钮点击事件
- (void)btnAct:(UIButton *)btn{
//UIApplication是系统单例,可以直接使用
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
//AppDelegate里将所有东西(包括根视图,navigation,tabbar等)封装到自定义的方法loadDDmenuController里
[appDelegate loadDDmenuController];
}
在到AppDelegate里写判断
导入引导页的头文件
#import "LSStartViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//使用NSUserDefaults记录一下
NSString *isFirstLaunch = [[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstLaunch"];
if ([isFirstLaunch isEqualToString:@"NO"]) {
//不是第一次启动程序,不再加载引导页,直接进入应用程序
[self loadDDmenuController];
}else{
//第一次启动程序,加载引导页
LSStartViewController *start = [[LSStartViewController alloc] init];
self.window.rootViewController = start;
[start release];
//设置isFirstLaunch为NO,说明已经走过引导页了,以后在进入App就不会走这里了
[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"isFirstLaunch"];
}
[_window release];
return YES;
}
这样一个简单的引导页就完成了.