美文网首页
UICollectionView属性使用

UICollectionView属性使用

作者: lltree | 来源:发表于2018-07-30 15:56 被阅读12次
//初始化Layout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize =  CGSizeMake(kRecommendCellWidth, kRecommendCellHeight);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //flowLayout.minimumLineSpacing = 15;  //竖向间隔
    flowLayout.minimumInteritemSpacing  = 10;//水平间隔
    flowLayout.sectionInset = UIEdgeInsetsMake(0,15,0,15);//一个section 上左下右间隔

    //初始化collectionView
    UICollectionView *collectionView =[[UICollectionView alloc] initWithFrame:CGRectMake(0, 58, MainScreenWidth, kRecommendCellHeight) collectionViewLayout:flowLayout];
    _collectionView = collectionView;
    [self.contentView addSubview:collectionView];
    
    self.collectionView.dataSource = self;
    self.collectionView.delegate  =  self;
    
    self.collectionView.bounces       = YES;
    self.collectionView.scrollEnabled = YES;
    
    self.collectionView.backgroundColor = [UIColor yellowColor];
    
    //注册cell
    [self.collectionView registerClass:[GJFCHomeRecommendCollectionViewCell class] forCellWithReuseIdentifier:kReuseID];

相关文章

网友评论

      本文标题:UICollectionView属性使用

      本文链接:https://www.haomeiwen.com/subject/pkpfvftx.html