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

  • 相关阅读:
    mysql的查询、子查询及连接查询
    面向对象知识点续及单例模式
    PSR-2 编码风格规范
    PSR-1 基础编码规范
    博客园文章添加版权信息的方法
    微博第三方登陆接入流程
    使用EasyWechat快速开发微信公众号支付
    Git版本管理工具的使用
    E: Could not get lock /var/lib/apt/lists/lock
    ubuntu安装opencv
  • 原文地址:https://www.cnblogs.com/isItOk/p/4784671.html
Copyright © 2011-2022 走看看