iOS开发------设置欢迎页

 _welcomeScrollView=[[UIScrollView  alloc] initWithFrame:CGRectMake(0, 0, WIDTH(self.view), HEIGHT(self.view))];
    _welcomeScrollView.contentSize=CGSizeMake(WIDTH(self.view)*4, HEIGHT(self.view));
    _welcomeScrollView.pagingEnabled=YES;
    _welcomeScrollView.delegate=self;
    _welcomeScrollView.bounces=NO;
    _welcomeScrollView.showsHorizontalScrollIndicator=NO;
    _welcomeScrollView.showsHorizontalScrollIndicator=NO;
    [self.view  addSubview:_welcomeScrollView];
    _welcomeScrollView.sd_layout.widthIs(ScreenWidth).heightIs(ScreenHeight).leftSpaceToView(self.view,0).rightSpaceToView(self.view,0).bottomSpaceToView(self.view,0);
    for (int i=0; i<4; i++)
    {
        UIImageView*imageView;
        if ((NSInteger)AutoLayoutUIScreenWidth(1.0) < 1)
        {
            imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"ic_yingdaoyue_%d",i + 1]]];
        }else
        {
            imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"ic_yingdaoyue_%d",i + 1]]];
        }
        
        imageView.frame = CGRectMake(i*WIDTH(self.view), 0, WIDTH(self.view), HEIGHT(self.view));
        [_welcomeScrollView addSubview:imageView];
    }
    /**
     *  启动页按钮
     */
    UIButton *enterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    enterBtn.frame = CGRectMake(WIDTH(self.view)*3+WIDTH(self.view)/2-AutoLayoutUIScreenWidth(60.0) , HEIGHT(self.view)-AutoLayoutUIScreenHeight(80.0), AutoLayoutUIScreenWidth(120.0), AutoLayoutUIScreenHeight(40.0));
    enterBtn.tag = 1001;
    [enterBtn setBackgroundImage:[UIImage imageNamed:@"ic_llijietitan_h"] forState:UIControlStateNormal];
   // [enterBtn setBackgroundColor:[UIColor redColor]];
    [enterBtn addTarget:self action:@selector(enterBtnPressed) forControlEvents:UIControlEventTouchUpInside];
    //[enterBtn setTitle:LocalString(@"button_first_try") forState:UIControlStateNormal];
    if ((int)AutoLayoutUIScreenWidth(1.0) < 1)
    {
        enterBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    //[enterBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_welcomeScrollView addSubview:enterBtn];
}

-(void)initPageControl{
    
    /**
     *  分页控制器
     */
    _welcomePageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(WIDTH(self.view)/2-AutoLayoutUIScreenWidth(75.0), HEIGHT(self.view)-AutoLayoutUIScreenHeight(40.0), AutoLayoutUIScreenWidth(150.0), AutoLayoutUIScreenHeight(30.0))];
    _welcomePageControl.backgroundColor = [UIColor whiteColor];
    _welcomePageControl.numberOfPages = 4;
    _welcomePageControl.currentPage=0;
    _welcomePageControl.pageIndicatorTintColor = [UIColor whiteColor];
    _welcomePageControl.currentPageIndicatorTintColor = [UIColor redColor];
    [_welcomePageControl addTarget:self action:@selector(pageControlCurrentPage) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_welcomePageControl];
}

- (void)enterBtnPressed
{
    //点击由引导页进入主页
    NSLog(@"enterBtnPressed----");
    setUserDefault(KEY_IS_FIRST_USE_APP,[NSNumber numberWithBool:YES]);
    LoginViewController *loginVC = [[LoginViewController alloc]init];
   NavigationController *navigationControl = [[NavigationController alloc]initWithRootViewController:loginVC];
    [self presentViewController: navigationControl animated:YES completion:nil];

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int  page=_welcomeScrollView.contentOffset.x/WIDTH(self.view);
    _welcomePageControl.currentPage=page;
}

-(void)pageControlCurrentPage
{
    NSInteger  pages =_welcomePageControl.currentPage;
    [_welcomeScrollView  setContentOffset:CGPointMake(WIDTH(self.view)*(pages+1), 0)];
}

 

转载于:https://www.cnblogs.com/qinxiaoguang/p/5534878.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值