KWMClothingSetsHeader.m 3.68 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9 10
//
//  KWMClothingSetsHeader.m
//  iCemarose
//
//  Created by HouWeiBin on 2017/7/10.
//  Copyright © 2017年 kollway. All rights reserved.
//

#import "KWMClothingSetsHeader.h"
#import "KWMClothingSetsCell.h"
houweibin committed
11
#import "UIImageView+WebCache.h"
houweibin committed
12
#import "UIView+Prettify.h"
houweibin committed
13 14 15 16 17 18 19

@interface KWMClothingSetsHeader()

@property (nonatomic,weak) IBOutlet UIView *vView;

@property (nonatomic,weak) IBOutlet UICollectionView *cvSets;

houweibin committed
20 21
@property (nonatomic,weak) IBOutlet UIImageView *ivHeader;

houweibin committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
@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;
    
houweibin committed
67 68
    [self setShadow:CGSizeMake(0,2) shadowRadius:4 shadowOpacity:0.1 shadowColor:[UIColor blackColor]];
    
houweibin committed
69 70 71 72 73 74 75 76 77 78
    [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;
    
}

houweibin committed
79 80 81 82 83 84 85 86
-(void)setProductArray:(NSArray *)productArray{
    _productArray = productArray;
    [self.cvSets reloadData];
}

-(void)setHeaderImage:(NSString *)headerImage{
    _headerImage = headerImage;
    NSURL *imageURL = [NSURL URLWithString:headerImage];
lee committed
87
//    self.ivHeader.contentMode = UIViewContentModeScaleToFill;
houweibin committed
88 89 90 91
    [self.ivHeader sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
}


houweibin committed
92 93 94
#pragma mark - UICollectionViewDataSource
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    KWMClothingSetsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMClothingSetsCell class]) forIndexPath:indexPath];
houweibin committed
95 96 97
    
    BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
    cell.product = product;
houweibin committed
98
    cell.isMore = indexPath.row == 9;
houweibin committed
99
    
houweibin committed
100 101 102 103
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
houweibin committed
104
    CGSize size = CGSizeMake(66, 117);
houweibin committed
105 106 107 108 109 110 111 112
    return size;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
houweibin committed
113 114 115
    if(self.productArray && self.productArray.count > 9){
        return 10;
    }
houweibin committed
116
    return self.productArray?self.productArray.count:0;
houweibin committed
117 118
}

lee committed
119
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
houweibin committed
120 121 122 123 124
    if(indexPath.row == 9){
        [self.delegate kwm_gotoClothingSetsPage];
    }else{
        [self.delegate kwm_onClickProduct:self.productArray[indexPath.item]];
    }
lee committed
125 126
}

houweibin committed
127 128

@end