码迷,mamicode.com
首页 > 其他好文 > 详细

自定义引导视图

时间:2014-09-13 22:39:26      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:分页控件   style   blog   color   io   ar   for   div   sp   

#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;
}

 

自定义引导视图

标签:分页控件   style   blog   color   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/hw140430/p/3970381.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!