import "yindaoViewController.h"
import "ViewController.h"
@interface yindaoViewController ()<UIScrollViewDelegate>
{
UIScrollView *scrollV;
NSArray *imgArr;
}
@end
@implementation yindaoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 滾動(dòng)視圖圖
scrollV = [[UIScrollView alloc]initWithFrame:self.view.frame];
// 設(shè)置代理
scrollV.delegate =self;
// 將scroll 添加到加入到視圖上
[self.view addSubview:scrollV];
// 圖片數(shù)組
imgArr = @[@"1",@"2",@"3",@"4"];
// 使用for 來(lái)循環(huán)設(shè)置圖片
for(int i =0; i <4; i++)
{
// 設(shè)置圖片框
UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width *i,0, self.view.frame.size.width, self.view.frame.size.height)];
// 設(shè)置圖片
imgV.image = [UIImage imageNamed:imgArr[i]];
// 允許與用戶交互
imgV.userInteractionEnabled = YES;
if(i == 3){
// 按鈕
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 600, 200, 40)];
// 標(biāo)題
[btn setTitle:@"立即體驗(yàn)" forState:UIControlStateNormal];
// 按鈕顏色
btn.backgroundColor = [UIColor redColor];
//按鈕文字顏色
[btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
// 添加事件
[btn addTarget:self action:@selector(GoTo) forControlEvents:UIControlEventTouchUpInside];
[imgV addSubview:btn];
}
[scrollV addSubview:imgV];
}
// 設(shè)置滾動(dòng)范圍
scrollV.contentSize = CGSizeMake(self.view.frame.size.width *4, self.view.frame.size.height);
// 設(shè)置分頁(yè)滾動(dòng)
scrollV.pagingEnabled = YES;
// 隱藏水平滾動(dòng)條
scrollV.showsHorizontalScrollIndicator =NO;
}
-(void)GoTo{
ViewController *main = [ViewController new];
// 采取從下往上的方式跳轉(zhuǎn)
[self presentViewController:main animated:YES completion:nil];
}
@end
在AppDelegate里初始化剛才的頁(yè)面