?滾動(dòng)視圖
UIScrollView *scroll;//滾動(dòng)視圖
NSArray *imgArr;//圖片數(shù)組
UIPageControl *page;//分頁控件
//創(chuàng)建滾動(dòng)視圖
? ? scroll = [[UIScrollView alloc]initWithFrame:self.view.frame];
? ? //設(shè)置代理
? ? scroll.delegate = self;
? ? //將滾動(dòng)視圖添加到視圖
? ? [self.view addSubview:scroll];
? ? //創(chuàng)建圖片數(shù)組
? ? imgArr = @[@"1",@"2",@"3",@"4"];
? ? //使用for循環(huán)添加圖片框 設(shè)置圖片
? ? for (int i = 0; i < 4; i++) {
? ? ? ? //創(chuàng)建圖片框
? ? ? ? UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i,0, self.view.frame.size.width, self.view.frame.size.height)];
? ? ? ? //設(shè)置圖片
? ? ? ? imgView.image = [UIImage imageNamed:imgArr[i]];
? ? ? ? //是否允許與用戶交互
? ? ? ? imgView.userInteractionEnabled = YES;
? ? ? ? //判斷最后一張圖片就顯示立即體驗(yàn)按鈕
? ? ? ? if (i == 3) {
? ? ? ? ? ? //創(chuàng)建立即體驗(yàn)按鈕
? ? ? ? ? ? UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ? ? ? ? ? //設(shè)置位置
? ? ? ? ? ? btn.frame = CGRectMake((self.view.frame.size.width - 100)/ 2, 600, 100, 44);
? ? ? ? ? ? //設(shè)置按鈕文字
? ? ? ? ? ? [btn setTitle:@"立即體驗(yàn)" forState:UIControlStateNormal];
? ? ? ? ? ? //添加事件
? ? ? ? ? ? [btn addTarget:self action:@selector(dicCilckBtn) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? ? ? //設(shè)置圓角
? ? ? ? ? ? btn.layer.cornerRadius = 8;
? ? ? ? ? ? //裁剪邊框
? ? ? ? ? ? btn.layer.masksToBounds = YES;
? ? ? ? ? ? //設(shè)置邊框
? ? ? ? ? ? btn.layer.borderWidth = 1;
? ? ? ? ? ? btn.layer.borderColor = [UIColor cyanColor].CGColor;
? ? ? ? ? ? //將按鈕添加到圖片上
? ? ? ? ? ? [imgView addSubview:btn];
? ? ? ? }
? ? ? ? //將圖片框添加到滾動(dòng)視圖中
? ? ? ? [scroll addSubview:imgView];
? ? }
? ? //設(shè)置滾動(dòng)范圍
? ? scroll.contentSize = CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height);
? ? //設(shè)置分頁滾動(dòng)
? ? scroll.pagingEnabled = YES;
? ? //取消彈簧效果
? ? scroll.bounces = NO;
? ? //隱藏水平滾動(dòng)條
? ? scroll.showsHorizontalScrollIndicator = NO;
? ? //創(chuàng)建分頁控件
? ? page = [[UIPageControl alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 100)/2, 670, 100, 30)];
? ? //設(shè)置分頁
? ? page.numberOfPages = 4;
? ? //設(shè)置當(dāng)前頁碼顏色
? ? page.currentPageIndicatorTintColor = [UIColor redColor];
? ? //設(shè)置分頁顏色
? ? page.pageIndicatorTintColor = [UIColor blackColor];
? ? //添加到視圖
? ? [self.view addSubview:page];
}
//滾動(dòng)視圖的協(xié)議方法----當(dāng)滾動(dòng)結(jié)束的時(shí)候調(diào)用
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
? ? //將滾動(dòng)頁數(shù)和滾動(dòng)視圖關(guān)聯(lián)
? ? page.currentPage = scroll.contentOffset.x / self.view.frame.size.width;
}
-(void)dicCilckBtn{
? ? TabBarViewController *tabBar = [[TabBarViewController alloc]init];
? ? [self presentViewController:tabBar animated:YES completion:nil];
}