#import "GoodsToSaleViewCell.h"

#import "GoodsOnSaleController.h"
#import "GoodsToSaleViewCell.h"
@interface GoodsOnSaleController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSIndexPath *selectedIndexPath;
@end
@implementation GoodsOnSaleController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
self.view.backgroundColor = [UIColor whiteColor];
[self setCollectionView];
}
#pragma mark - setUI
- (void)setCollectionView {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
self.collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.view addSubview:self.collectionView];
// 注册cell
[self.collectionView registerNib:[UINib nibWithNibName:@"GoodsToSaleViewCell" bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([GoodsToSaleViewCell class])];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
GoodsToSaleViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([GoodsToSaleViewCell class]) forIndexPath:indexPath];
if (indexPath == _selectedIndexPath) {
cell.layer.borderColor = selectedColor.CGColor;
}else{
cell.layer.borderColor = normalColor.CGColor;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
GoodsToSaleViewCell *cell = (GoodsToSaleViewCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];
if (_selectedIndexPath == indexPath) {
cell.layer.borderColor = normalColor.CGColor;
_selectedIndexPath = nil;
}else{
if (_selectedIndexPath != nil) {
GoodsToSaleViewCell *selectedCell = (GoodsToSaleViewCell *)[self collectionView:collectionView cellForItemAtIndexPath:_selectedIndexPath];
selectedCell.layer.borderColor = normalColor.CGColor;
}
self.selectedIndexPath = indexPath;
cell.layer.borderColor = selectedColor.CGColor;
}
[self.collectionView reloadData];
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath == _selectedIndexPath) {
return CGSizeMake(self.collectionView.frame.size.width - 20, 175);
}
return CGSizeMake(self.collectionView.frame.size.width - 20, 100);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
浙公网安备 33010602011771号