轮播图

作者: 偏执_cbbe | 来源:发表于2017-07-27 21:10 被阅读0次

#import "ViewController.h"

#import "zongViewController.h"

@interface ViewController ()

{

UIScrollView * theScroll;

NSArray * theArr;

UIPageControl * thePage;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.view.backgroundColor=[UIColor whiteColor];

//初始化一个滚动视图

theScroll = [[UIScrollView alloc]initWithFrame:self.view.frame];

//设置代理

theScroll.delegate = self;

//设置按页滚动

theScroll.pagingEnabled = YES;

//设置是否显示滚动条

theScroll.showsHorizontalScrollIndicator = NO;

//加载

[self.view addSubview:theScroll];

theArr = @[@"shiwu1.jpg",@"shiwu2.jpg",@"shiwu3.jpg"];

CGFloat x = 0.0;

for (int i = 0; i < theArr.count; i++) {

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

theImageView.image = [UIImage imageNamed:theArr[i]];

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

[theScroll addSubview:theImageView];

if(i==theArr.count -1)

{

UIButton *but=[[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width -100)/2, 550, 100, 40)];

[but setTitle:@"立即体验" forState:UIControlStateNormal];

[but setBackgroundColor:[UIColor colorWithRed:29/250.0 green:170/250.0 blue:230/250.0 alpha:1.0]];

[but addTarget:self action:@selector(tz) forControlEvents:UIControlEventTouchUpInside];

but.layer.cornerRadius=10;

but.layer.masksToBounds=YES;

theImageView.userInteractionEnabled=YES;

[theImageView addSubview:but];

}

}

theScroll.contentSize = CGSizeMake(x, self.view.frame.size.height);

//初始化一个分页控制器

thePage = [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-30, self.view.frame.size.height/5*4, 60, 20)];

//设置分页控制器的个数

thePage.numberOfPages = theArr.count;

//设置分页控制器的颜色

thePage.pageIndicatorTintColor = [UIColor grayColor];

//设置分页控制器选中时的颜色

thePage.currentPageIndicatorTintColor = [UIColor redColor];

//加载

[self.view addSubview:thePage];

//----------------------------------

}

//实现分页控制器与滚动视图的关联

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

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

}

-(void)tz

{

zongViewController *v1=[zongViewController new];

[self presentViewController:v1 animated:YES completion:^{}];

}

相关文章

  • 无标题文章

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。它们各具特色,各有用处。 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/cjrnkxtx.html