iOS 卡片效果 轮播图效果

Demo地址:https://github.com/ColdChains/RecycleView.git

demo已上传Cocoapods,使用:pod 'RecycleView'

上半部分为卡片效果,下半部分为轮播图效果,仿UITableview通过代理设置数据源

请添加图片描述

使用方式与UITableView和UICollectionView一样,实现QLRecycleViewDelegate、QLRecycleViewDataSource两个协议里的方法

@protocol LCRecycleViewDelegate <NSObject, UIScrollViewDelegate>

@optional

// 返回cell的大小
- (CGSize)sizeForItemInRecycleView:(LCRecycleView *)recycleView;

// 点击某个cell
- (void)recycleView:(LCRecycleView *)recycleView didSelectItemAtIndex:(NSInteger)index;

@end
@protocol LCRecycleViewDataSource <NSObject>

// 返回Cell的数量
- (NSInteger)numberOfItemsInRecycleView:(LCRecycleView *)recycleView;

// 返回Cell样式
- (UIView *)recycleView:(LCRecycleView *)recycleView cellForItemAtIndex:(NSInteger)index;

@end

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 卡片效果
    LCRecycleView *recycleView = [[LCRecycleView alloc] init];
    recycleView.delegate = self;
    recycleView.dataSource = self;
    recycleView.edgeInsets = UIEdgeInsetsMake(0, 18, 0, 18);
    recycleView.minSpacing = 12;
    recycleView.canLoop = NO;
    recycleView.tag = 100;
    
    [self.view addSubview:recycleView];
    [recycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(88);
        make.height.mas_equalTo(100);
    }];
    
    // 轮播图效果
    LCRecycleView *bannerView = [[LCRecycleView alloc] init];
    bannerView.delegate = self;
    bannerView.dataSource = self;
    bannerView.edgeInsets = UIEdgeInsetsMake(0, 18, 0, 18);
    bannerView.minSpacing = 12;
    bannerView.canLoop = YES;
    
    LCPageControl *control = [[LCPageControl alloc] init];
    control.backgroundColor = [UIColor lightGrayColor];
    control.pageIndicatorTintColor = [UIColor redColor];
    control.currentPageIndicatorTintColor = [UIColor whiteColor];
    control.delegate = bannerView;
    bannerView.pageControl = control;
    
    [self.view addSubview:bannerView];
    [bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(recycleView.mas_bottom).offset(44);
        make.height.mas_equalTo(333);
    }];
}

// 返回数量
- (NSInteger)numberOfItemsInRecycleView:(LCRecycleView *)recycleView {
    return recycleView.tag == 100 ? 10 : 3;
}

// 返回大小
- (CGSize)sizeForItemInRecycleView:(LCRecycleView *)recycleView {
    return recycleView.tag == 100 ? CGSizeMake(100, 100) : CGSizeMake(UIScreen.mainScreen.bounds.size.width - 18 * 2, 333);
}

// 返回样式
- (UIView *)recycleView:(LCRecycleView *)recycleView cellForItemAtIndex:(NSInteger)index {
    UIImageView *cell = (UIImageView *)[recycleView dequeueReusableCell];
    if (!cell) {
        cell = [[UIImageView alloc] init];
    }
    cell.backgroundColor = @[[UIColor greenColor], [UIColor orangeColor], [UIColor redColor]][index % 3];
    return cell;
}

// 点击
- (void)recycleView:(LCRecycleView *)recycleView didSelectItemAtIndex:(NSInteger)index {
    NSLog(@"%ld", index);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值