无限滚动 UICollectionView

注意拖控件的时候 一定注意代理的实现

 

 

 

//

//  ViewController.m

//  ImageView

//

//  Created by Lenny on 4/18/15.

//  Copyright (c) 2015 Lenny Kwok. All rights reserved.

//

 

#import "ViewController.h"

#import "LKImageCell.h"

 

#define Identifier @"collectionCell"

 

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    //进行cell的注册

     // 注册cell(如果缓存池中没有HMCellIdentifier对应的cell,就会自动创建HMCellIdentifier对应的注册过的cell)

    [self.collectionView registerClass:[LKImageCell class] forCellWithReuseIdentifier:Identifier];

}

 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return  16;

}

 

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    LKImageCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:Identifier forIndexPath:indexPath];

    cell.icon = [NSString stringWithFormat:@"minion_%02ld",indexPath.item + 1];

    return cell;

}

 

@end

 

 

 

 

 

//

//  LKImageCell.m

//  ImageView

//

//  Created by Lenny on 4/18/15.

//  Copyright (c) 2015 Lenny Kwok. All rights reserved.

//

 

#import "LKImageCell.h"

 

 

@interface LKImageCell ()

@property(nonatomic,weak) UIImageView * imageView;

 

@end

@implementation LKImageCell

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

        UIImageView * imageView = [[UIImageView alloc]init];

        [self addSubview:imageView];

        self.imageView = imageView;

    }

    return self;

}

-(void)setIcon:(NSString *)icon

{

    _icon = [icon copy];

    self.imageView.image = [UIImage imageNamed:icon];

}

-(void)layoutSubviews

{

    [super layoutSubviews];

    CGFloat x = 5;

    CGFloat y = 0;

    CGFloat w = self.bounds.size.width - 2 * x;

    CGFloat h = self.bounds.size.height;

    self.imageView.frame = CGRectMake(x, y, w, h);

}

@end

 

 

 

 

//

//  LKImageCell.h

//  ImageView

//

//  Created by Lenny on 4/18/15.

//  Copyright (c) 2015 Lenny Kwok. All rights reserved.

//

 

#import <UIKit/UIKit.h>

 

@interface LKImageCell : UICollectionViewCell

@property(nonatomic , copy) NSString * icon;

 

@end



转载于:https://www.cnblogs.com/LennyKwok/p/4438193.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值