ui--CollectionViewCell

.介绍

    集合视图,iOS6之后出现的视图控件,与UITableView类似,最大的特点是可以对cell实现灵活的布局

UICollectionView使用的cellUICollectionViewCell


注意:self.automaticallyAdjustsScrollViewInsets =NO;


2.UICollectionViewFlowLayout 

介绍:UICollectionViewFlowLayout系统提供的,能够实现cell的网格布局

UICollectionViewFlowLayout的父类是UICollectionViewLayoutUICollectionViewLayout集合视图的布局类,是一个抽象基类

1)@property (nonatomic)UICollectionViewScrollDirection scrollDirection

设置collectionView的方向

UICollectionViewScrollDirectionVertical 竖直

  UICollectionViewScrollDirectionHorizontal 水平

2)@property (nonatomic)CGFloat  minimumLineSpacing;

设置横向的最小间隔


3)@property (nonatomic)CGFloat minimumInteritemSpacing;

设置纵向的最小间隔


注意:如果CollectionView垂直滚动,横向的最小间隔能直接生效;纵向的最小间隔由实际间隔需要根据itemsizeedgesInsets的值来调节


3.UICollectionView基本方法和属性 

1)- (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout

利用布局对象,实现集合视图的初始化

2)@property (nonatomic,assign) id <UICollectionViewDelegate> delegate

设置代理UICollectionViewDelegateFlowLayout


3)@property (nonatomic,assign) id <UICollectionViewDataSource> dataSource;

设置代理UICollectionViewDataSource


4.UICollectionView代理方法


cell的方法

1)- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

指定每一个item的大小


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

一个section有多少个Item(cell)


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

返回Cell

(1)Cell的注册方法

- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier

   - (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier

(2)Cell取出的方式

- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath

通过重用标识符和indexPathUICollectionView的重用队列中获取cell对象,因为已经提前注册了cell,如果获取不到cell对象,UICollectionView会根据注册的cell样式,自动创建cell对象



4)- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

cell被选中的时候调用的方法


section的方法

5)- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

设置组的个数


6)- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section

   设置顶部view的高度。如果垂直滚动,viewwidth与集合视图一致,需要设置高度


7)- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section

设置底部view的高度 


8)- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

通过此方法为sectionheaderViewfooterView赋值

(1)注册方法

- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;

  注册的种类

UICollectionElementKindSectionHeader 

设置sectionHeaderView

UICollectionElementKindSectionFooter 

设置SectionFooterView

(2)取出的方式

- (id)dequeueReusableSupplementaryViewOfKind:(NSString*)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath

通过此方法为sectionheaderViewfooterView赋值

    用下面方法判断是header还是footer

[kindisEqualToString:UICollectionElementKindSectionHeader]


cell整体边距

9)- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section

描述的是所有cell相对于另一个视图上、左、下、右的距离



补充:[[UIDevice currentDevice].systemVersion floatValue]

获取系统版本号

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值