IDNLoopView 图片/视图循环播放控件

IDNLoopView 图片/视图循环播放控件

github地址: https://github.com/photondragon/IDNLoopView

IDNLoopView演示

这个控件有如下特点:

  1. 可实现图片或视图的无限循环播放
  2. 支持任意类型视图,包括但不限于UIImageView
  3. 支持运行时动态改变IDNLoopView控件的大小
  4. 当Touch时,自动播放定时器会重置
  5. 使用方法类似UITableView,没有学习成本

使用方法

先将源文件IDNLoopView.hIDNLoopView.m加入项目中,具体用法跟UITableView差不多,示例代码如下:

#import "ViewController.h"
#import "IDNLoopView.h"

@interface ViewController ()
<IDNLoopViewDelegate,
IDNLoopViewDataSource>

@property (weak, nonatomic) IBOutlet IDNLoopView *loopView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.loopView.datasource = self;
    self.loopView.delegate = self;
//  self.loopView.reuseDisabled = YES; //关闭view回收机制
//  self.loopView.pageControl.hidden = YES; //隐藏内置的UIPageControl
//  self.loopView.intervalTime = 0; //关闭自动切换
//  self.loopView.currentIndex = 2;
}

#pragma mark IDNLoopView DataSource & Delegate

- (NSInteger)numberOfViewsInLoopView:(IDNLoopView *)loopView
{
    return 6;
}

- (UIView*)loopView:(IDNLoopView *)loopView viewAtIndex:(NSInteger)index reuseView:(UIView *)view
{
    UIImageView* imageView;
    if(view==nil)
    {
        imageView = [[UIImageView alloc] init];
    }
    else
        imageView = (UIImageView*)view;

    NSString* imgfile = [NSString stringWithFormat:@"抽象派艺术%03d.jpg", (int)index];
    NSLog(@"%@", imgfile);
    imageView.image = [UIImage imageNamed:imgfile];

    return imageView;
}

- (void)loopView:(IDNLoopView *)loopView didTapViewAtIndex:(NSInteger)index
{
    NSLog(@"tap index = %d", (int)index);
}

- (void)loopView:(IDNLoopView *)loopView didShowViewAtIndex:(NSInteger)index
{
    NSLog(@"current index = %d", (int)index);
}

@end

如果要显示网络图片,可配合SDWebImage使用,修改数据源方法- loopView:viewAtIndex:reuseView:如下:

- (UIView*)loopView:(IDNLoopView *)loopView viewAtIndex:(NSInteger)index reuseView:(UIView *)view
{
    UIImageView* imageView;
    if(view==nil)
    {
        imageView = [[UIImageView alloc] init];
    }
    else
        imageView = (UIImageView*)view;

    static UIImage* placeholder = nil;
    if(placeholder==nil)
        placeholder = [UIImage imageNamed:@"imageLoading.jpg"];

    [imageView sd_setImageWithURL:[NSURL URLWithString:self.images[index]] placeholderImage:placeholder];

    return imageView;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值