_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)];
}