美文网首页
2016-07-30

2016-07-30

作者: 灬槑 | 来源:发表于2018-07-30 07:56 被阅读0次

 滚动视图

UIScrollView *scroll;//滚动视图

NSArray *imgArr;//图片数组

UIPageControl *page;//分页控件

//创建滚动视图

    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 < 4; 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(dicCilckBtn) forControlEvents:UIControlEventTouchUpInside];

            //设置圆角

            btn.layer.cornerRadius = 8;

            //裁剪边框

            btn.layer.masksToBounds = YES;

            //设置边框

            btn.layer.borderWidth = 1;

            btn.layer.borderColor = [UIColor cyanColor].CGColor;

            //将按钮添加到图片上

            [imgView addSubview:btn];

        }

        //将图片框添加到滚动视图中

        [scroll addSubview:imgView];

    }

    //设置滚动范围

    scroll.contentSize = CGSizeMake(self.view.frame.size.width * 4, 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)/2, 670, 100, 30)];

    //设置分页

    page.numberOfPages = 4;

    //设置当前页码颜色

    page.currentPageIndicatorTintColor = [UIColor redColor];

    //设置分页颜色

    page.pageIndicatorTintColor = [UIColor blackColor];

    //添加到视图

    [self.view addSubview:page];

}

//滚动视图的协议方法----当滚动结束的时候调用

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    //将滚动页数和滚动视图关联

    page.currentPage = scroll.contentOffset.x / self.view.frame.size.width;

}

-(void)dicCilckBtn{

    TabBarViewController *tabBar = [[TabBarViewController alloc]init];

    [self presentViewController:tabBar animated:YES completion:nil];

}

相关文章

  • Eco靓词赏析(5)

    本期选自The Economist 2016-07-30 United States come through 达...

  • 2016-07-30

    滚动视图 UIScrollView *scroll;//滚动视图 NSArray *imgArr;//图片数组 U...

  • Eco靓词赏析(6)

    本期选自The Economist 2016-07-30, Books and arts板块 card-carry...

  • Eco靓词赏析(4)

    本期选自The Economist 2016-07-30 loss-making 经常亏损的,无利的,not ma...

  • 手把手教你封装网络层

    作者:Tomasz Szulc,原文链接,原文日期:2016-07-30译者:智多芯;校对:Crystal Sun...

  • 1.基于AVPlayer基本的视频播放

    直接上代码 屏幕快照 2016-07-30 上午10.21.04.png ViewController.h Vie...

  • 如果没有“如果”

    2016-07-30 12:53:554 路过的故事 “啊?你说什么?你不要吓我啊…” 忽然就听到这姑娘咋呼的声音...

  • 微信好友,信任从哪里来?...

    原创 2016-07-30 文明 张文明 微信是熟人社交,商务沟通必备;你微信上的点滴反映了你的形象、品位、格局。...

  • 爱的银行存款——吉他二人组

    D27 2016-07-30 老公,晚上你带女儿洗完澡,本来到了睡觉的时间,而女儿吵着要和你吉他弹唱,于是你们又拿...

  • 说爱其三

    鹏澍 | 2016-07-30 “人生只此一次的爱恋”,这话对,也是不对。有的人因爱之甜蜜而成瘾,也有的人会因爱之...

网友评论

      本文标题:2016-07-30

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