zoukankan      html  css  js  c++  java
  • UICollectionViewController用法

     // 初始化
        UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc]init];
        UICollectionView *myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 100, view.width-20, 90) collectionViewLayout:flowLayout];
        myCollectionView.backgroundColor = [UIColor grayColor];
        [myCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"myCell"];
         myCollectionView.delegate = self;
         myCollectionView.dataSource = self;
        myCollectionView.backgroundColor = [UIColor whiteColor];
         [view addSubview:myCollectionView];
    
    #pragma mark - collectionView delegate
    
    //每个分区上的元素个数
    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
        return 10;
    }
    
    //设置元素内容
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
         UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
      
        UIImageView *emojiView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 24, 24)];
        emojiView.backgroundColor = [UIColor redColor];
        [cell.contentView addSubview:emojiView];
        
        return cell;
    }
    
    //设置元素的的大小框
    -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
    {
         return UIEdgeInsetsMake(10, 10, 10, 10);
    }
    
    // 设定指定Cell的尺寸
    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
        return CGSizeMake(24.0,24.0);
    }
    
    // 设定指定区内Cell的最小行距
    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
    {
        return 20.0;
    }
    
    // 设定指定区内Cell的最小间距
    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
    {
        return 20.0;
    }
    
    // item被选择时触发
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"%ld",indexPath.row);
    }
  • 相关阅读:
    [io PWA] keynote: Launching a Progressive Web App on Google.com
    hdu 4491 Windmill Animation
    BNU Concentric Rings
    Android 如何去掉手机中横竖屏切换时的转屏动画?
    IOS NSString 用法详解
    MySQL有关1042 Can’t get hostname for your address的问题分析解决过程
    网站出现问题时,站长该如何解决
    [置顶] IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
    具备这5点因素,你就是一名合格的网络编辑
    IOS 新消息通知提示-声音、震动
  • 原文地址:https://www.cnblogs.com/joesen/p/4331624.html
Copyright © 2011-2022 走看看