zoukankan      html  css  js  c++  java
  • UI整理-----part5--UICollectionView

    (1)可以理解成多列的UITableView(这是UICollectionView的最简单的形式)

    (2)实现一个UICollectionView和实现一个UITableView基本没什么大区别,它们同样都是由dataSource和delegate设计模式的:dataSource为View提供数据源,delegate提供一些样式的小细节以及用户交互响应

    (3)保证CollectionView正常工作的三个方法:

    - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView        section的数量

    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section          某个section里有多少item

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath              对于某个位置应该显示什么样的cell

    (4)UICollectionViewCell的布局是由UICollectionViewLayout类的子类 UICollectionViewFlowLayout 决定的:

    {

        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

        layout.itemSize = CGSizeMake(100, 100);

        layout.minimumInteritemSpacing = 20;  //设置单元格水平间隔,默认为10

        layout.minimumLineSpacing = 20;      //设置行间距为20

        layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);   //设置与边框距离

        layout.scrollDirection = UICollectionViewScrollDirectionVertical;  //设置滚动方向

        layout.headerReferenceSize = CGSizeMake(0, 200);     //设置头部视图大小只需要设置height 

    }

    (5)在创建完布局类之后,需要实现实例化一个UICollectionView

        UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];

    (6)通过注册的方式创建单元格头视图    [collectionViewregisterClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];     其中:UICollectionReusableView——collectionView共用的类   UICollectionElementKindSectionHeader——注册头视图的类型

    (7)触摸事件:- (void)collectionView:(UICollectionView *)collectionViewdidSelectItemAtIndexPath:(NSIndexPath *)indexPath

  • 相关阅读:
    HDU 3586 Information Disturbing (树形DP,二分)
    HDU 4274 Spy's Work (树形DP,模拟)
    HDU 4276 The Ghost Blows Light (树形DP,变形)
    ZOJ 3627 Treasure Hunt II (贪心,模拟)
    ZOJ 3626 Treasure Hunt I (树形DP,常规)
    POJ 2104 K-th Number (区间第k大)
    HDU 4044 GeoDefense (树形DP,混合经典)
    POJ 2486 Apple Tree (树形DP,树形背包)
    HDU 4003 Find Metal Mineral (树形DP,经典)
    TinyMCE
  • 原文地址:https://www.cnblogs.com/8023huihui/p/5203983.html
Copyright © 2011-2022 走看看