UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 29, DEVICE_SCREEN_WIDTH, DEVICE_SCREEN_HEIGHT-DEVICE_STATUS_BAR_HEIGHT-DEVICE_NAVIGATION_BAR_HEIGHT - 29) collectionViewLayout:flowLayOut];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = COLOR_HEX(0xf7f7f7, 1.0);
[self.view addSubview:_collectionView];
[_collectionView registerNib:[UINib nibWithNibName:@"InstallUnitCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"InstallUnitCollectionViewCell"];
pragma mark ---- UICollectionViewDataSource
-
(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
InstallUnitCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"InstallUnitCollectionViewCell" forIndexPath:indexPath];
return cell;
} -
(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
} -
(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{return 5;
} -
(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
pragma mark ---- UICollectionViewDelegateFlowLayout
-
(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize size = CGSizeMake((DEVICE_SCREEN_WIDTH-40)/3, (DEVICE_SCREEN_WIDTH-40)/3);
return size;
} -
(UIEdgeInsets)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
//左右的又兼具
return UIEdgeInsetsMake(10,10, 0, 0);
}
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
//{
// //上下距离
// return 10;
//
//}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0.0001;
}
网友评论