// // KWMClothingSetsHeader.m // iCemarose // // Created by HouWeiBin on 2017/7/10. // Copyright © 2017年 kollway. All rights reserved. // #import "KWMClothingSetsHeader.h" #import "KWMClothingSetsCell.h" #import "UIImageView+WebCache.h" #import "UIView+Prettify.h" @interface KWMClothingSetsHeader() @property (nonatomic,weak) IBOutlet UIView *vView; @property (nonatomic,weak) IBOutlet UICollectionView *cvSets; @property (nonatomic,weak) IBOutlet UIImageView *ivHeader; @end @implementation KWMClothingSetsHeader +(NSString *)kwmTag{ return @"KWMClothingSetsHeader"; } - (id)init{ if (self=[super init]){ [self addView]; } return self; } - (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { [self addView]; } return self; } -(instancetype)initWithFrame:(CGRect)frame{ if (self =[super initWithFrame:frame]) { [self addView]; } return self; } -(void)addView{ [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil]; self.vView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); [self addSubview:self.vView]; [self initView]; } -(void)initView{ self.cvSets.delegate = self; self.cvSets.dataSource = self; [self setShadow:CGSizeMake(0,2) shadowRadius:4 shadowOpacity:0.1 shadowColor:[UIColor blackColor]]; [self.cvSets registerNib:[UINib nibWithNibName:NSStringFromClass([KWMClothingSetsCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([KWMClothingSetsCell class])]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init]; layout.minimumLineSpacing = 20; layout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 0); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.cvSets.collectionViewLayout = layout; } -(void)setProductArray:(NSArray *)productArray{ _productArray = productArray; [self.cvSets reloadData]; } -(void)setHeaderImage:(NSString *)headerImage{ _headerImage = headerImage; NSURL *imageURL = [NSURL URLWithString:headerImage]; self.ivHeader.contentMode = UIViewContentModeScaleToFill; [self.ivHeader sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]]; } #pragma mark - UICollectionViewDataSource -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ KWMClothingSetsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMClothingSetsCell class]) forIndexPath:indexPath]; BUYProduct *product = [self.productArray objectAtIndex:indexPath.row]; cell.product = product; cell.isMore = indexPath.row == 9; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGSize size = CGSizeMake(66, 117); return size; } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if(self.productArray && self.productArray.count > 9){ return 10; } return self.productArray?self.productArray.count:0; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == 9){ [self.delegate kwm_gotoClothingSetsPage]; }else{ [self.delegate kwm_onClickProduct:self.productArray[indexPath.item]]; } } #pragma mark - action -(IBAction) focusImageAction:(id)sender { [self.delegate kwm_onClickFocusImage]; } @end