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

  • 相关阅读:
    【转】JSON.parse() Unexpected token i in JSON at position 2 报错问题
    修改json对象的每一个值
    浏览器各个版本和系统(chrome/safari/edge/qq/360)
    数据库书籍推荐排行榜
    git-将dev代码合并到test
    npm install报错
    slice()和splice()区别
    在Eclipse中使用JUnit4进行单元测试(初级篇)
    [转载]Jmeter那点事·ForEach和If控制器
    java语言写文件内容
  • 原文地址:https://www.cnblogs.com/isItOk/p/4784671.html
Copyright © 2011-2022 走看看