基于UIScrollView和UIPageControl控件做的用户引导界面

来源:互联网 发布:淘宝满减券漏洞 编辑:程序博客网 时间:2024/05/01 12:37

效果图片

#import "RootViewController.h"@interface RootViewController ()<UIScrollViewDelegate>@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.    self.view.backgroundColor = [UIColor grayColor];    /**     *  UIpageControl     1.表示页数.     2.表示当前正处于第几页     3.点击切换页数.     *     */    //存储用户的偏好设置,存储在本地,比如:程序是不是第一次加载    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];    if (![userDefaults boolForKey:@"aa"]) {        [self setupFirstLanchView];        [userDefaults setBool:YES forKey:@"aa"];        //立即同步        [userDefaults synchronize];    }}//创建程序第一次运行要加载的视图- (void)setupFirstLanchView{    [self setupScrollView];    [self setupPageControl];}- (void)setupScrollView{    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];    scrollView.tag = 200;//    scrollView.maximumZoomScale = 4.0;//    scrollView.minimumZoomScale = 1.0;    scrollView.showsHorizontalScrollIndicator = YES;//关闭水平滑动线    scrollView.pagingEnabled = YES;//设置整屏滑动    scrollView.contentSize = CGSizeMake(320*6, [UIScreen mainScreen].bounds.size.height);    scrollView.delegate = self;//设置代理    [self.view addSubview:scrollView];    [scrollView release];        for (int i = 0; i < 6; i++) {        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(320*i , 0, 320,[UIScreen mainScreen].bounds.size.height)];        imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"v6_guide_%d",i+1] ofType:@"png"]];        [scrollView addSubview:imageView];        [imageView release];    }}- (void)setupPageControl{    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, [UIScreen mainScreen].bounds.size.height - 40, 300, 20)];    pageControl.tag = 100;    //pageControl.backgroundColor = [UIColor whiteColor];    //设置页数    pageControl.numberOfPages = 6;    //设置当前的点    pageControl.currentPage = 0;    //设置未选中点的颜色    pageControl.pageIndicatorTintColor = [UIColor orangeColor];    //设置选中点的颜色    pageControl.currentPageIndicatorTintColor = [UIColor blackColor];    //添加响应事件    [pageControl addTarget:self action:@selector(handlePageControl:) forControlEvents:UIControlEventValueChanged];    [self.view addSubview:pageControl];    [pageControl release];}- (void)handlePageControl:(UIPageControl *)pageControl{    //切换pageControl,对应切换scrollView不同的界面    UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:200];    //contentOffset偏移量    [scrollView setContentOffset:CGPointMake(320 * pageControl.currentPage, 0) animated:YES];}- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{    UIPageControl *pageControl = (UIPageControl *)[self.view viewWithTag:100];    pageControl.currentPage = scrollView.contentOffset.x/320;}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end


0 0
原创粉丝点击