当前位置: 首页 > news >正文

茶具网站模板html5电影网站建设

茶具网站模板,html5电影网站建设,个人网站建设优化,vi设计网站排行榜轮播图为一种常见的方式#xff0c;常用于各种网站#xff0c;或者App中#xff0c;当然#xff0c;作为APP的启动视图也是不错的选择。 闲时封装了一个#xff0c;仅供新手参考。 1.新建工程#xff0c;建立轮播图类 建立一个空的工程#xff0c;新建一个类#xff0c…轮播图为一种常见的方式常用于各种网站或者App中当然作为APP的启动视图也是不错的选择。 闲时封装了一个仅供新手参考。 1.新建工程建立轮播图类 建立一个空的工程新建一个类起名为Carousel继承于UIView 2.编写Carousel类接口 1 interface Carousel : UIView2 typedef NS_ENUM(NSInteger,UICarouselPageType){3 //建立一个枚举型来设置Carousel的样式4 UICarouselPageTypeCenter,//设置pageControl在中心5 UICarouselPageTypeLeft, //设置pageControl在左侧6 UICarouselPageTypeRight, //设置pageControl在右侧7 };8 property(nonatomic,strong)NSArray *ImageArry;//用于接收来自外部的图片9 property(nonatomic,assign)NSTimeInterval duration;//用于接收每张图片的持续时间 10 property(nonatomic,assign)UICarouselPageType PageType; 11 end 3.内部代码 1.用懒加载的方式定义UIScrollView和UIPageControl   (1)为Carousel类建立延展   1 interface Carousel()UIScrollViewDelegate 2 property(nonatomic,strong)UIScrollView *scroll; 3 property(nonatomic,strong)UIPageControl *pageControl; 4 property(nonatomic,assign)int index; 5 property(nonatomic,strong)NSTimer *timer; 6 end      (2)重写初始化方法 1 -(instancetype)initWithFrame:(CGRect)frame{ 2 self [super initWithFrame:frame]; 3 if (self) { 4 _timer [[NSTimer alloc]init]; 5 _index0; 6 } 7 return self; 8 }   3scrollView 1 -(UIScrollView *)scroll{2 if (_scrollnil) {3 _scroll [[UIScrollView alloc]initWithFrame:self.bounds];4 _scroll.delegateself;5 _scroll.contentSizeCGSizeMake([_ImageArry count]*WIDTH,HEIGHT);6 _scroll.pagingEnabledYES;//允许整页翻动7 _scroll.bouncesNO;8 _scroll.showsHorizontalScrollIndicatorNO;9 _scroll.showsVerticalScrollIndicatorNO; 10 for (int i0; i[_ImageArry count]; i) { 11 UIImageView *imageView [[UIImageView alloc]initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, HEIGHT)]; 12 UIImage *image[_ImageArry objectAtIndex:i]; 13 imageView.imageimage; 14 [_scroll addSubview:imageView]; 15 } 16 } 17 return _scroll; 18 }    (4)pageControl 1 -(UIPageControl *)pageControl{2 if (_pageControl nil) {3 _pageControl [[UIPageControl alloc]init];4 [self setPageControlFrame];5 _pageControl.numberOfPages[_ImageArry count];6 _pageControl.pageIndicatorTintColor[UIColor greenColor];7 _pageControl.currentPageIndicatorTintColor[UIColor redColor];8 [_pageControl addTarget:self action:selector(change:) forControlEvents:UIControlEventValueChanged];9 } 10 return _pageControl; 11 } 12 -(void)setPageControlFrame{ 13 //当PageType有不同值的时候 有不同的frame 14 if (_PageTypeUICarouselPageTypeLeft) { 15 _pageControl.frameCGRectMake(0,HEIGHT-20,150,20); 16 }else if (_PageType UICarouselPageTypeRight){ 17 _pageControl.frameCGRectMake(WIDTH-150,HEIGHT-20,150,20); 18 }else{ 19 _pageControl.frameCGRectMake(WIDTH/2-75,HEIGHT-20,150,20); 20 } 21 } 22 -(void)change:(UIPageControl *)page{ 23 [_timer invalidate]; 24 _timernil; 25 _scroll.contentOffsetCGPointMake(page.currentPage*WIDTH, 0); 26 _index(int)page.currentPage;//重新给index赋值 27 _timer [NSTimer scheduledTimerWithTimeInterval:_duration target:self selector:selector(lunbo) userInfo:nil repeats:YES]; 28 }     (5) 重写ImageArray的set方法 1 -(void)setImageArry:(NSArray *)ImageArry{ 2 //重写Set方法 当ImageArray有值的时候显示scrollView和PageControl 3 if (_ImageArry!ImageArry) { 4 _ImageArry ImageArry; 5 [self addSubview:self.scroll]; 6 [self addSubview:self.pageControl]; 7 _timer [NSTimer scheduledTimerWithTimeInterval:_duration target:self selector:selector(lunbo) userInfo:nil repeats:YES]; 8 } 9 }   (6)Scroll的代理方法 1 -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{2 //开始拖动时销毁计时器3 [_timer invalidate];4 _timer nil;5 }6 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{7 //减速结束时重新生成计时器8 _index(int)_pageControl.currentPage;//重新给index赋值9 _timer [NSTimer scheduledTimerWithTimeInterval:_duration target:self selector:selector(lunbo) userInfo:nil repeats:YES]; 10 } 11 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ 12 _pageControl.currentPagescrollView.contentOffset.x/WIDTH; 13 }  4.应用Carousel类 1 #import ViewController.h2 #import Carousel.h3 interface ViewController ()4 end5 implementation ViewController6 7 - (void)viewDidLoad {8 [super viewDidLoad];9 Carousel *lunbo [[Carousel alloc]initWithFrame:CGRectMake(0, 100, 414, 300)]; 10 NSMutableArray *arr[[NSMutableArray alloc]initWithCapacity:9]; 11 for (int index1; index10; index) { 12 UIImage *image [UIImage imageNamed:[NSString stringWithFormat:%d.jpg,index]]; 13 [arr addObject:image]; 14 } 15 lunbo.duration1; 16 lunbo.PageTypeUICarouselPageTypeCenter; 17 lunbo.ImageArryarr; 18 [self.view addSubview:lunbo]; 19 // Do any additional setup after loading the view, typically from a nib. 20 }   效果图    转载于:https://www.cnblogs.com/pangxuhui/p/5671957.html
http://www.zqtcl.cn/news/890360/

相关文章:

  • 企业网站维护wordpress特效代码
  • 建设银行网站短信错误6次wordpress新主题去版权
  • 国外 配色网站天猫店购买交易平台
  • 网站推广广告词大全集网站和网络建设自查报告
  • 电子商务网站建设备案须知自己做的网站服务器在哪里
  • 怎样用wordpress做网站wordpress 首页判断
  • jsp做的网站效果织梦网站程序模板
  • 展示型网站设计公司网盘wordpress
  • 网站建设 保密学服装设计后悔了
  • 网站建设前端和后端网站开发所遵循的
  • 有自己域名的个人网站企业网站建设制作公司
  • 工程行业网站优化网站推广排名
  • 青岛网站建设软件下载广州app网站建设
  • 天津市建设厅官方网站qq电脑版登录
  • 贵阳手机网站建设公司辽源网站建设
  • 淄博网站设计制作wordpress 纯静态首页
  • 规划电子商务网站流程福清建设局网站简介
  • 使用joomla的网站网络营销师资格证有什么用
  • 做经营网站怎么赚钱吗关于做网站的合同
  • 上海手机网站建设哪家好重庆景点
  • 做网站菜单背景图片wordpress伪原创词库
  • 网络维护工程师工资多少聊城哪里做优化网站
  • 网站开发用什么字体查询域名备案
  • 济南品牌网站建设公司网站单个页面紧张搜索引擎蜘蛛
  • 公司需要一个简单的网站包头网站建设奥北
  • 怎么制作网站导航页新手做网站详细步骤
  • 自己个人网站后台怎么做wordpress多程序用户同步
  • 赣州网联科技有限公司wordpress安装后优化
  • 二手书的网站建设做设计在哪个网站找图片大全
  • 网站seo设计北京市建设投标网站