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

#import "KWMNewHomeCell.h"
#import "UIView+Prettify.h"
houweibin committed
11 12 13
#import "KWMStringUtil.h"
#import "KWMImageUtil.h"
#import "UIImageView+WebCache.h"
houweibin committed
14 15
#import "NSLayoutConstraint+Multiplier.h"
#import "UIColor+SAMAdditions.h"
u  
lee committed
16
#import "KWMRuleView.h"
houweibin committed
17

houweibin committed
18 19 20

@interface KWMNewHomeCell()

u  
lee committed
21 22 23
@property(nonatomic,strong) KWMRuleView *ruleView;
@property (weak, nonatomic) IBOutlet UIButton *ruleBtn;

houweibin committed
24 25 26 27 28 29
@property(nonatomic,weak) IBOutlet UILabel *lbBrand;

@property(nonatomic,weak) IBOutlet UILabel *lbName;

@property(nonatomic,weak) IBOutlet UILabel *lbPrice;

houweibin committed
30 31
@property(nonatomic,weak) IBOutlet UIImageView *ivProduct;

houweibin committed
32 33 34 35 36
@property(nonatomic,weak) IBOutlet UIView *vImageContentView;

@property(nonatomic,weak) IBOutlet NSLayoutConstraint *heightDetail;

@property(nonatomic,weak) IBOutlet NSLayoutConstraint *precentOfProductImageView;
u  
lee committed
37 38
@property (weak, nonatomic) IBOutlet UIView *closeRuleView;

houweibin committed
39

houweibin committed
40 41 42 43 44 45 46
@end

@implementation KWMNewHomeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.vContent initDefaultShadow];
u  
lee committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    [self initRuleView];
}

-(void) initRuleView {
    
    _ruleView = [[KWMRuleView alloc] initWithFrame:CGRectMake((UI_SCREEN_WIDTH-70)/2, 0, (UI_SCREEN_WIDTH-70)/2, (UI_SCREEN_WIDTH-70)/2)];
    [_vImageContentView addSubview:_ruleView];
    _vImageContentView.layer.masksToBounds = YES;
}

-(IBAction)openRuleView:(id)sender {
    if (_ruleView.frame.origin.x) {
        [UIView animateWithDuration:0.25 animations:^{
            _ruleView.frame = CGRectMake(0, 0, (UI_SCREEN_WIDTH-70)/2, (UI_SCREEN_WIDTH-70)/2);
            self.closeRuleView.hidden = NO;
            self.ruleBtn.selected = YES;
        }];
    }
houweibin committed
65
}
u  
lee committed
66 67 68 69 70 71 72 73 74 75
- (IBAction)closeRuleView:(id)sender {
    if (!_ruleView.frame.origin.x) {
        [UIView animateWithDuration:0.25 animations:^{
            _ruleView.frame = CGRectMake((UI_SCREEN_WIDTH-70)/2, 0, (UI_SCREEN_WIDTH-70)/2, (UI_SCREEN_WIDTH-70)/2);
            self.closeRuleView.hidden = YES;
            self.ruleBtn.selected = NO;
        }];
    }
}

houweibin committed
76

houweibin committed
77 78 79
-(void)setSingleShow:(BOOL)singleShow{
    if(singleShow){
        NSTextAlignment textAlignment = NSTextAlignmentCenter;
houweibin committed
80 81 82 83 84
        self.lbBrand.textAlignment = textAlignment;
        self.lbName.textAlignment = textAlignment;
        self.lbPrice.textAlignment = textAlignment;
        self.lbName.numberOfLines = 1;
        self.lbBrand.numberOfLines = 1;
houweibin committed
85 86
//        self.precentOfProductImageView = [self.precentOfProductImageView updateMultiplier:1];
//        self.vImageContentView.backgroundColor = [UIColor sam_colorWithHex:@"F1929A"];
houweibin committed
87 88 89
    }
}

houweibin committed
90

houweibin committed
91 92
-(void)setProduct:(BUYProduct *)product{
    _product = product;
u  
lee committed
93 94 95
    _ruleView.frame = CGRectMake((UI_SCREEN_WIDTH-70)/2, 0, (UI_SCREEN_WIDTH-70)/2, (UI_SCREEN_WIDTH-70)/2);
    self.closeRuleView.hidden = YES;
    self.ruleBtn.selected = NO;
houweibin committed
96 97 98 99 100 101 102 103
    if(product){
        NSString *imageUrl = [KWMImageUtil getProductImageUrl:product ImageSize:SmallImage];
        NSURL *imageURL = [NSURL URLWithString:imageUrl];
        [self.ivProduct sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
        self.lbBrand.text = product.vendor;
        self.lbName.text = product.title;
        if(product.variantsArray.count>0){
            BUYProductVariant *variant = product.variantsArray.firstObject;
lee committed
104 105
//            self.lbPrice.text = [KWMStringUtil price:variant.price];
            self.lbPrice.text = variant.price.priceValueFormatted;
houweibin committed
106
        }
u  
lee committed
107
        [self.ruleView setData:product];
houweibin committed
108 109 110 111 112
    }
}

+(NSInteger)acturlHeight:(BUYProduct *)product width:(NSInteger)width{
    NSInteger lbNameWidth = width - 60;
houweibin committed
113
    UIFont *font = [UIFont systemFontOfSize:9];
houweibin committed
114
    if(SYSTEM_VERSION_LESS_THAN(@"9.0")){
houweibin committed
115
        [UIFont fontWithName:@"PingFang SC" size:9];
houweibin committed
116 117
    }
    NSInteger lbNameHeight = [KWMStringUtil getLabelHeight:product.title labelFont:font textWidth:lbNameWidth].height;
houweibin committed
118
    return width + 50 +lbNameHeight;
houweibin committed
119 120 121
}

@end