美文网首页
iOS引导页面(点击进入主界面的)

iOS引导页面(点击进入主界面的)

作者: ViewController_ | 来源:发表于2018-11-22 22:38 被阅读0次

    首先定义几个全局属性

    {
    UIScrollView *scroll;//滚动视图
    NSArray *imgarr;//图片数组
    UIPageControl *page;//分页
    }

    在viewDidLoad里:

    //创建滚动视图
    scroll = [[UIScrollView alloc]initWithFrame:self.view.frame];
    //代理
    scroll.delegate = self;
    //添加到视图
    [self.view addSubview:scroll];
    //图片数组
    imgarr = @[@"1",@"2",@"3",@"4"];//添加图片
    //for循环添加图片
    for (int i = 0; i < imgarr.count; i++)
    {
    //创建图片框
    UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width *i, 0, self.view.frame.size.width, self.view.frame.size.height)];
    //设置图片
    imgview.image = [UIImage imageNamed:imgarr[i]];
    //是否与用户交互
    imgview.userInteractionEnabled = YES;
    //判断,最后一张图片就添加按钮
    if (i == 3)
    {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //设置按钮位置
    btn.frame = CGRectMake((self.view.frame.size.width - 100)/2, 600, 100, 44);
    //按钮文字
    [btn setTitle:@"立即体验" forState:UIControlStateNormal];
    //注册监听事件
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchDown];
    //设置圆角
    btn.layer.cornerRadius = 8;
    //裁剪
    btn.layer.masksToBounds = YES;
    //背景颜色
    btn.backgroundColor = [UIColor blueColor];
    //添加到视图
    [imgview addSubview:btn];
    }
    //添加到滚动视图
    [scroll addSubview:imgview];
    }
    //设置吧滚动范围
    scroll.contentSize = CGSizeMake(self.view.frame.size.width *imgarr.count, self.view.frame.size.height);
    //设置分页效果
    scroll.pagingEnabled = YES;
    //去除弹窗效果
    scroll.bounces = NO;
    //隐藏水平滚动条
    scroll.showsHorizontalScrollIndicator = NO;
    //创建分页控件
    page = [[UIPageControl alloc]initWithFrame:CGRectMake((self.view.frame.size.width)-100, 650, 100, 30)];
    //设置分页个数
    page.numberOfPages = imgarr.count;

    //隐藏tabbar和navigation
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;

    在下面点击事件:

    -(void)click{

    //取消隐藏tabbar和navigation
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
    

    //在里面写内容

    }

    相关文章

      网友评论

          本文标题:iOS引导页面(点击进入主界面的)

          本文链接:https://www.haomeiwen.com/subject/cdorqqtx.html