IOS用户引导界面示例
jopen
10年前
// RootViewController.m // LessonUIPageControl // Copyright (c) 2014年 Summer summer2014mht@sina.com. All rights reserved. #import"RootViewController.h" @interfaceRootViewController ()<UIScrollViewDelegate> @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNilbundle:nibBundleOrNil]; if (self) { // Custom initialization } returnself; } - (void)viewDidLoad { [superviewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColoryellowColor]; //存储用户的偏好设置,存储在本地,比如:程序是否是第一次加载 NSUserDefaults *userDefaults = [NSUserDefaultsstandardUserDefaults]; if (![userDefaults boolForKey:@"aa"]) { [selfsetupFirstLanchView]; [userDefaultssetBool:YESforKey:@"aa"]; //立即同步 [userDefaultssynchronize]; } } //创建程序第一次加载要显示的视图 - (void)setupFirstLanchView { [selfsetupScrollView]; [selfsetupPageControl]; } - (void)setupScrollView { UIScrollView *scrollView = [[UIScrollViewalloc]initWithFrame:[UIScreenmainScreen].bounds]; scrollView.delegate =self; [self.viewaddSubview:scrollView]; //关闭水平方向上的滚动条 scrollView.showsHorizontalScrollIndicator =NO; //是否可以整屏滑动 scrollView.pagingEnabled =YES; scrollView.tag =200; [scrollViewrelease]; scrollView.contentSize =CGSizeMake(320 *6, [UIScreen mainScreen].bounds.size.height); for (int i = 0; i < 6; i++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(320 * i,0,320, [UIScreenmainScreen].bounds.size.height)]; imageView.image = [UIImageimageWithContentsOfFile:[[NSBundlemainBundle]pathForResource:[NSStringstringWithFormat:@"v6_guide_%d", i +1]ofType:@"png"]]; [scrollViewaddSubview:imageView]; [imageViewrelease]; } } - (void)setupPageControl { /** * UIPageControl 1.表示页数 2.表示当前正处于第几页 3.点击切换页数 */ UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, [UIScreenmainScreen].bounds.size.height -40, 300, 20)]; pageControl.tag =100; //设置表示的页数 pageControl.numberOfPages =6; //设置选中的页数 pageControl.currentPage =0; //设置未选中点的颜色 pageControl.pageIndicatorTintColor = [UIColorgrayColor]; //设置选中点的颜色 pageControl.currentPageIndicatorTintColor = [UIColorblackColor]; //添加响应事件 [pageControladdTarget:selfaction:@selector(handlePageControl:)forControlEvents:UIControlEventValueChanged]; [self.viewaddSubview:pageControl]; [pageControlrelease]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { UIPageControl *pagControl = (UIPageControl *)[self.view viewWithTag:100]; pagControl.currentPage = scrollView.contentOffset.x / 320; } - (void)handlePageControl:(UIPageControl *)pageControl { //切换pageControl .对应切换scrollView不同的界面 UIScrollView *scrollView = (UIScrollView *)[self.viewviewWithTag:200]; // [scrollViewsetContentOffset:CGPointMake(320 * pageControl.currentPage,0)animated:YES]; } - (void)didReceiveMemoryWarning { [superdidReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */