zoukankan      html  css  js  c++  java
  • collectionView代码创建

    @interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

    @property(nonatomic,strong)UICollectionView * collectionView;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view.    

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

        self.collectionView = [[UICollectionView alloc] initWithFrame: CGRectMake(10, 65, 屏幕宽度 - 20, 屏幕高度 - 65)

                                                  collectionViewLayout:layout];

        self.collectionView.delegate = self;

        self.collectionView.dataSource = self;

        [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];

        self.collectionView.backgroundColor = [UIColor clearColor];

        [self.view addSubview:self.collectionView];

    }

    #pragma mark UICollectionViewDataSource

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

        return 6;

    }

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

        

        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];

           //cell加载数据

        return cell;

    }

    #pragma mark UICollectionViewDelegateFlowLayout

    - (CGSize)collectionView:(UICollectionView *)collectionView

                      layout:(UICollectionViewLayout*)collectionViewLayout

      sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

        CGFloat w = (屏幕宽度 - 20 - 30 - 1) / 4;//每一行放四个

        return CGSizeMake(w, w);

    }

    - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView

                            layout:(UICollectionViewLayout*)collectionViewLayout

            insetForSectionAtIndex:(NSInteger)section{

        return UIEdgeInsetsMake(0, 0, 0, 0);

    }

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

            return CGSizeMake(0, 10);

    }

    - (void)collectionView:(UICollectionView *)collectionView

    didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

     // 点击事件

    }

    @end

  • 相关阅读:
    Winform Treeview 的按需加载
    Dynamic CRM 2013学习笔记(十)客户端几种查询数据方式比较
    Dynamic CRM 2013学习笔记(九)CrmFetchKit.js介绍:Fetchxml、多表联合查询, 批量更新
    Dynamic CRM 2013学习笔记(八)过滤查找控件 (类似省市联动)
    iOS Programming
    Hello Socket
    解决ARC的循环引用问题
    解决Eclipse下不自动拷贝apk到模拟器问题( The connection to adb is down, and a severe error has occured)
    解决Android NDK 报jxxx编译找不到
    做一个创建cocos2d-x新项目的shell脚本
  • 原文地址:https://www.cnblogs.com/isItOk/p/4784671.html
Copyright © 2011-2022 走看看