zoukankan      html  css  js  c++  java
  • UICollectionView

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        CGFloat itemWidth = (self.view.bounds.size.width - margin*3) / 2;

        CGFloat itemHeight = itemWidth * 0.85 + 100;

        

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

        layout.itemSize = CGSizeMake(itemWidth, itemHeight);

        layout.minimumInteritemSpacing = margin;

        layout.minimumLineSpacing = margin;

        layout.sectionInset = UIEdgeInsetsMake(margin, margin, margin, margin);

        

        self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];

        [self.view addSubview:self.collectionView];

        self.collectionView.dataSource = self;

        self.collectionView.delegate = self;

        self.collectionView.backgroundColor = [UIColor whiteColor];

        [self.collectionView registerClass:[HomeCell class] forCellWithReuseIdentifier:HYSquareHotViewCellIdentifier];

    }

    #pragma mark Delegate & DataSource

    - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

    {

        return 1;

    }

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

    {

        return 10;

    }

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

    {

        HomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HYSquareHotViewCellIdentifier forIndexPath:indexPath];

        cell.backgroundColor = [UIColor colorWithRed:((10 * indexPath.row) / 255.0) green:((20 * indexPath.row)/255.0) blue:((30 * indexPath.row)/255.0) alpha:1.0f];

        return cell;

    }

    1
  • 相关阅读:
    JAVA自学之-----FileInputStream类
    RandomAccessFile类的使用(随机读取java中的文件)
    JAVA File常用的API介绍
    Java中的编码
    java的装箱与拆箱
    java基础知识整理:
    java程序编写需注意的问题
    iPhone开机键坏了如何开机
    WKInterfaceTable实例化出现的一系列
    Office for Mac
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5313574.html
Copyright © 2011-2022 走看看