iOS引导页面(点击进入主界面的)
2019-01-03 本文已影响0人
盖世英雄的梦想
import "yindaoViewController.h"
import "ViewController.h"
@interface yindaoViewController ()<UIScrollViewDelegate>
{
UIScrollView *scrollV;
NSArray *imgArr;
}
@end
@implementation yindaoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 滚动视图图
scrollV = [[UIScrollView alloc]initWithFrame:self.view.frame];
// 设置代理
scrollV.delegate =self;
// 将scroll 添加到加入到视图上
[self.view addSubview:scrollV];
// 图片数组
imgArr = @[@"1",@"2",@"3",@"4"];
// 使用for 来循环设置图片
for(int i =0; i <4; i++)
{
// 设置图片框
UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width *i,0, self.view.frame.size.width, self.view.frame.size.height)];
// 设置图片
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)];
// 标题
[btn setTitle:@"立即体验" 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];
}
// 设置滚动范围
scrollV.contentSize = CGSizeMake(self.view.frame.size.width *4, self.view.frame.size.height);
// 设置分页滚动
scrollV.pagingEnabled = YES;
// 隐藏水平滚动条
scrollV.showsHorizontalScrollIndicator =NO;
}
-(void)GoTo{
ViewController *main = [ViewController new];
// 采取从下往上的方式跳转
[self presentViewController:main animated:YES completion:nil];
}
@end
在AppDelegate里初始化刚才的页面