首页 > 代码库 > 自定义引导视图

自定义引导视图

#pragma mark - 创建引导页+ (id)initWithFrame:(CGRect)frame{    return [[self alloc] initWithFrame:frame];}//- (id)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self) {          //1.创建滚动视图        _scrollView = [[UIScrollView alloc]initWithFrame:frame];        _scrollView.contentSize = CGSizeMake(kCount * kScreenW, kZero);        _scrollView.showsHorizontalScrollIndicator = NO;        _scrollView.bounces = NO;        _scrollView.delegate = self;        _scrollView.pagingEnabled = YES;        [self addSubview:_scrollView];                //2.创建引导页图片        _guideImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kZero, kZero, kScreenW * 4, kScreenH)];        [_scrollView addSubview:_guideImageView];                //3.创建进入主界面的按钮        _intoMainViewBtn = [[UIButton alloc] init];        [_intoMainViewBtn addTarget:self action:@selector(intoMainView) forControlEvents:UIControlEventTouchUpInside];        //4.创建分页控件        _pageControl = [[UIPageControl alloc] init];        _pageControl.enabled = NO;        _pageControl.bounds = CGRectMake(kZero, 5, 150, 50);        _pageControl.numberOfPages = kCount;        _pageControl.pageIndicatorTintColor = [UIColor grayColor];        _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];                //5.设置按钮和分页控件的Frame        if (isIphone5) {            _guideImageView.image = [UIImage imageNamed:@"guide02"];            _intoMainViewBtn.frame = CGRectMake(kScreenW * 3 + 120, 355, 88, 150);            _pageControl.center = CGPointMake(kScreenW * 0.5, kScreenH - 20);                    }else{//iPhone4                        _guideImageView.image = [UIImage imageNamed:@"guide01"];            _intoMainViewBtn.frame = CGRectMake(kScreenW * 3 + 120, 305, 90, 130);            _pageControl.center = CGPointMake(kScreenW * 0.5 + 3, kScreenH - 10);        }        [_scrollView addSubview:_intoMainViewBtn];        [self addSubview:_pageControl];    }    return self;}#pragma mark - 当scrollView正在滚动的时候调用- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    //设置页码    currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;    _pageControl.currentPage = currentPage;}

 

自定义引导视图