152 lines
4.3 KiB
Objective-C
152 lines
4.3 KiB
Objective-C
//
|
|
// IfishAiLiShopGoodsViewCell.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 17/4/11.
|
|
// Copyright © 2017年 lianlian. All rights reserved.
|
|
//
|
|
|
|
#import "IfishAiLiShopGoodsViewCell.h"
|
|
#import "IfishBCShopItemCell.h"
|
|
#import "IfishGoodsData.h"
|
|
static NSString * const cellIdenti = @"IfishBCShopItemCell";
|
|
@implementation IfishAiLiShopGoodsViewCell
|
|
|
|
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
{
|
|
self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
|
|
if (self) {
|
|
|
|
|
|
[self creatCollection];
|
|
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
-(void)creatCollection{
|
|
|
|
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
|
flowLayout.minimumLineSpacing = 1;
|
|
flowLayout.minimumInteritemSpacing = .1;
|
|
|
|
CGFloat width = (kScreenSize.width-1)/2;
|
|
CGFloat itemH = width *1.38;
|
|
flowLayout.itemSize = CGSizeMake(width,itemH);
|
|
//展示两行
|
|
CGFloat HCELL= (itemH*1+1)*2;
|
|
|
|
_collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0,0,kScreenSize.width, HCELL) collectionViewLayout:flowLayout];
|
|
|
|
_collectionView.delegate=self;
|
|
_collectionView.dataSource=self;
|
|
_collectionView.bounces=NO;
|
|
_collectionView.scrollEnabled=NO;
|
|
_collectionView.showsVerticalScrollIndicator=NO;
|
|
_collectionView.backgroundColor = RGB(242, 242, 242);
|
|
[self addSubview:_collectionView];
|
|
|
|
[self.collectionView registerClass:[IfishBCShopItemCell class] forCellWithReuseIdentifier:cellIdenti];
|
|
UINib *cellNib=[UINib nibWithNibName:@"IfishBCShopItemCell" bundle:nil];
|
|
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:cellIdenti];
|
|
|
|
}
|
|
|
|
-(void)refreshCollellction{
|
|
|
|
CGFloat width = (kScreenSize.width-1)/2;
|
|
CGFloat itemH = width *1.38;
|
|
if (_goodsdataArr.count>4) {
|
|
|
|
int total = (int)[_goodsdataArr count];
|
|
int rowCount =total%2==0?total/2:total/2+1;
|
|
|
|
CGFloat HCELL= (itemH*1+1)*rowCount;
|
|
|
|
_collectionView.frame = CGRectMake(0,0,kScreenSize.width, HCELL);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#pragma mark <UICollectionViewDataSource>
|
|
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
|
return _goodsdataArr.count;
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
IfishBCShopItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdenti forIndexPath:indexPath];
|
|
IfishGoodsData *data = _goodsdataArr[indexPath.row];;
|
|
[cell loadCellData:data];
|
|
return cell;
|
|
}
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
// Initialization code
|
|
}
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
|
|
CGFloat width = (kScreenSize.width-1)/2;
|
|
CGFloat itemH = width *1.38;
|
|
CGSize itemSize = CGSizeMake(width,itemH);
|
|
return itemSize;
|
|
|
|
}
|
|
|
|
//距离上下左右的间距
|
|
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
|
|
{
|
|
|
|
|
|
return UIEdgeInsetsMake(0,0,0, 0);
|
|
|
|
}
|
|
|
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
|
|
{
|
|
//设置最小的列间距
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
|
|
{
|
|
//设置最小的行间距
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
if (_goodsdataArr.count==0) {
|
|
return;
|
|
}
|
|
if (self.delegate) {
|
|
IfishGoodsData *data = _goodsdataArr[indexPath.row];
|
|
[self.delegate tapTtemListAt:data.goodsLink];
|
|
}
|
|
|
|
}
|
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
|
[super setSelected:selected animated:animated];
|
|
|
|
// Configure the view for the selected state
|
|
}
|
|
|
|
@end
|