zoukankan      html  css  js  c++  java
  • 自定义引导视图

    #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;
    }
  • 相关阅读:
    JS正则表达式大全(整理详细且实用)
    你真的会使用XMLHttpRequest吗?
    pyCharm最新激活码(2018激活码)
    Hibernate 中配置属性详解(hibernate.properties)
    c3p0详细配置
    使用Git上传本地项目到http://git.oschina.net
    深入理解Java:注解(Annotation)自定义注解入门
    SpringMVC文件上传与下载
    C语言开发系列-二进制
    C开发系列-include
  • 原文地址:https://www.cnblogs.com/hw140430/p/3970381.html
Copyright © 2011-2022 走看看