麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

UICollectionView基礎

2019-11-14 18:41:56
字體:
來源:轉載
供稿:網友
 UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;//滾動方向
    flowLayout.minimumLineSpacing = 10.0;//行間距(最小值)
    flowLayout.minimumInteritemSpacing = 50.0;//item間距(最小值)
    flowLayout.itemSize = CGSizeMake(50, 50);//item的大小
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);//設置section的邊距
    flowLayout.headerReferenceSize = CGSizeMake(320, 20);
    flowLayout.footerReferenceSize = CGSizeMake(320, 20);
    //第二個參數是cell的布局
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 320, 568) collectionViewLayout:flowLayout];
    [flowLayout release];
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.backgroundColor = [UIColor orangeColor];
    //1 注冊復用cell(cell的類型和標識符)(可以注冊多個復用cell, 一定要保證重用標示符是不一樣的)注冊到了collectionView的復用池里
    [collectionView registerClass:[CLCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
     
    //第一個參數:返回的View類型
    //第二個參數:設置View的種類(header, footer)
    //第三個參數:設置重用標識符
   [collectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier];
    [collectionView registerClass:[FootView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footerIdentifier];
    [self.view addSubview:collectionView];
 
 
#PRagma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 10;
}
 
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //2 從復用池中找cell(1:cell的標示符 2:indexPath決定系統用不用再給你創建cell, 不用創建的話, 就直接使用之前的cell)
    CLCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor yellowColor];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
    return cell;
}
 
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (kind == UICollectionElementKindSectionHeader) {
        HeadView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerIdentifier forIndexPath:indexPath];
        headerView.textLabel.text = @"讓我組成頭部!";
        headerView.textLabel.textAlignment = NSTextAlignmentCenter;
        headerView.textLabel.textColor = [UIColor whiteColor];
        return headerView;
    }
    FootView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:footerIdentifier forIndexPath:indexPath];
    footerView.textLabel.text = @"讓我組成尾部!";
    footerView.textLabel.textAlignment = NSTextAlignmentCenter;
    footerView.textLabel.textColor = [UIColor whiteColor];
    return footerView;
}
 
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%d %d", indexPath.section, indexPath.row);
}
 
 
#pragma mark - UICollectionViewDelegateFlowLayout
/*
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
     
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
     
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
     
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
     
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
     
}
 */
 
 
 
 
 
 
 
 
 
 
    [collectionView registerClass:[FootView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footerIdentifier];
    [self.view addSubview:collectionView];

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 法国极品成人h版 | 久久经典免费视频 | 性高湖久久久久久久久aaaaa | 色播亚洲 | 成人午夜视频免费在线观看 | 欧美人的天堂一区二区三区 | 在线成人影视 | 久久久久久精 | 性看小视频 | 在线影院av | 性aaa| 亚洲综合网站 | 国产精品一区二区视频 | 韩国三级日本三级香港三级黄 | 2019中文字幕在线播放 | 日本免费a∨| 欧美一级高清免费 | 欧美一级片在线 | 九九黄色影院 | 成人在线免费视频观看 | 狠狠色噜噜狠狠狠米奇9999 | 色婷婷久久久 | 羞羞的视频免费在线观看 | 欧美精品成人一区二区三区四区 | 精品一区二区亚洲 | 视频www | 国产精品亚洲欧美一级在线 | 国产午夜精品久久久久久免费视 | 暴力肉体进入hdxxxx古装 | 国产合集91合集久久日 | 亚洲精品成人av在线 | 五月婷婷第四色 | 久久草在线视频国产 | 日本高清无遮挡 | 日本在线视频一区二区三区 | www国产成人免费观看视频 | 久久久久免费精品国产小说色大师 | 欧美人xxx| xxxx hd video 69| 久久精品视频2 | 鲁人人人鲁人人鲁精品 |