轮播图

作者: 9898a | 来源:发表于2017-09-21 09:15 被阅读0次

//创建数组

imgArr = [NSMutableArray arrayWithObjects:@"a.JPEG",@"w.JPG",@"e.JPEG",@"r.JPEG",@"t.jpeg",@"d.jpg", nil];

MessageArr = [NSMutableArray arrayWithObjects:@"爱你不是应为你的美",@"最爱你的人是我",@"你怎么舍得我难过",@"在你需要我的时候",@"我来陪你度过",@"这一生没有你怎么过", nil];

scrView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 300)];

scrView.backgroundColor = [UIColor orangeColor];

//添加图片

for (NSInteger i = 0, x=0; i<6; i++ ) {

//创建图片视图

UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, 300)];

//添加图片

image.image = [UIImage imageNamed:imgArr[i]];

//加入滚动视图

[scrView addSubview:image];

x +=self.view.frame.size.width;

}

//设置滚动视图的范围

scrView.contentSize =CGSizeMake(self.view.frame.size.width*4,300);

//是否按页滚动

scrView.pagingEnabled=YES;

//取消反弹

scrView.bounces=NO;

//设置隐藏滑动条

scrView.showsVerticalScrollIndicator=NO;

scrView.showsHorizontalScrollIndicator=NO;

scrView.delegate=self;

[self.view addSubview:scrView];

//初始化页码

thePage=[[UIPageControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width-130, 315, 100, 30)];

//设置页码个数

thePage.numberOfPages=6;

//设置页码初始页

thePage.currentPage=0;

//设置页码颜色

thePage.pageIndicatorTintColor=[UIColor blueColor];

//设置当前页码颜色

thePage.currentPageIndicatorTintColor=[UIColor yellowColor];

[thePage addTarget:self action:@selector(shsh) forControlEvents:UIControlEventTouchUpInside];

//把分页控件添加到视图上

[self.view addSubview:thePage];

//添加计时器

timer=[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerValueChange) userInfo:nil repeats:YES];

//触发

[timer fire];

number=0;

//计时器响应方法

-(void)timerValueChange

{

//设置偏移量

scrView.contentOffset=CGPointMake(self.view.frame.size.width*number, 0);

number++;

if (number == imgArr.count-1) {

number=0;

}

//    //    //点的大小                              为了把点 放到中间

//    [scrView setContentOffset:CGPointMake(number*scrView.frame.size.width, 0) animated:YES];

}

//实现页码和滚动视图的关联

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

//当前页  把滚动的页数与滚动控件进行关联

thePage.currentPage=scrView.contentOffset.x/self.view.frame.size.width;

}

//遵守两个协议方法

//表示在滑动滚动视图的时候调用此方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGPoint point=scrView.contentOffset;//偏移量

//当前点的第几张图片

thePage.currentPage=point.x/scrView.frame.size.width;

if (table.contentOffset.y/self.view.frame.size.height>0) {

self.navigationController.navigationBarHidden=YES;

scrView.hidden=NO;

}

else{

self.navigationController.navigationBarHidden=NO;

scrView.hidden=NO;

}

}

相关文章

  • 无标题文章

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。它们各具特色,各有用处。 1.传统轮播图 第一步...

  • 轮播图

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。 1.传统轮播图 第一步,得到元素 第二步,设置...

  • 现金红包

    每日红包 轮播图 详情图 周末红包 轮播图 详情图 圣诞红包 轮播图 详情图

  • day7_作业

    轮播图1 轮播图2

  • [iOS]定制性强的广告轮播图--SCAdView

    @[无限轮播图] @[3D轮播图] @[广告轮播图] SCAdView Statement If my code ...

  • 普通奖品

    卡西欧小方块 轮播图 详情图 三只松鼠大礼包 轮播图 详情图 天猫精灵 轮播图 详情图 小米蓝牙无线耳机 轮播图 ...

  • 轮播图心得

    轮播图 写轮播图之前我们要认识到几个问题:一、什么是轮播图?二、怎么实现轮播效果?三、轮播图还有什么小功能可以实现...

  • 第五周学习内容

    焦点图轮播特效之原理、焦点图轮播样式之布局、焦点图轮播之箭头切换、焦点图轮播之无限滚动。 js简介、用法、输出。

  • 三种样式的轮播图

    一、100%比例轮播图 HTML代码 CSS样式 js代码 二、手动箭头轮播图 三、简易轮播图

  • 多轮播图的设计

    列表展示多个轮播图 多个轮播图同时显示 多个轮播图不定时进行轮播动画 对应呈现的关系:1个TableView、一个...

网友评论

      本文标题:轮播图

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