// // KWMNewHomeCell.m // iCemarose // // Created by HouWeiBin on 2017/6/2. // Copyright © 2017年 kollway. All rights reserved. // #import "KWMNewHomeCell.h" #import "UIView+Prettify.h" #import "KWMStringUtil.h" #import "KWMImageUtil.h" #import "UIImageView+WebCache.h" #import "NSLayoutConstraint+Multiplier.h" #import "UIColor+SAMAdditions.h" #import "KWMRuleView.h" @interface KWMNewHomeCell() @property(nonatomic,strong) KWMRuleView *ruleView; @property (weak, nonatomic) IBOutlet UIButton *ruleBtn; @property(nonatomic,weak) IBOutlet UILabel *lbBrand; @property(nonatomic,weak) IBOutlet UILabel *lbName; @property(nonatomic,weak) IBOutlet UILabel *lbPrice; @property(nonatomic,weak) IBOutlet UIImageView *ivProduct; @property(nonatomic,weak) IBOutlet UIView *vImageContentView; @property(nonatomic,weak) IBOutlet NSLayoutConstraint *heightDetail; @property(nonatomic,weak) IBOutlet NSLayoutConstraint *precentOfProductImageView; @property (weak, nonatomic) IBOutlet UIView *closeRuleView; @end @implementation KWMNewHomeCell - (void)awakeFromNib { [super awakeFromNib]; [self.vContent initDefaultShadow]; [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; }]; } } - (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; }]; } } -(void)setSingleShow:(BOOL)singleShow{ if(singleShow){ NSTextAlignment textAlignment = NSTextAlignmentCenter; self.lbBrand.textAlignment = textAlignment; self.lbName.textAlignment = textAlignment; self.lbPrice.textAlignment = textAlignment; self.lbName.numberOfLines = 1; self.lbBrand.numberOfLines = 1; // self.precentOfProductImageView = [self.precentOfProductImageView updateMultiplier:1]; // self.vImageContentView.backgroundColor = [UIColor sam_colorWithHex:@"F1929A"]; } } -(void)setProduct:(BUYProduct *)product{ _product = product; _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; 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; // self.lbPrice.text = [KWMStringUtil price:variant.price]; self.lbPrice.text = variant.price.priceValueFormatted; } [self.ruleView setData:product]; } } +(NSInteger)acturlHeight:(BUYProduct *)product width:(NSInteger)width{ NSInteger lbNameWidth = width - 60; UIFont *font = [UIFont systemFontOfSize:9]; if(SYSTEM_VERSION_LESS_THAN(@"9.0")){ [UIFont fontWithName:@"PingFang SC" size:9]; } NSInteger lbNameHeight = [KWMStringUtil getLabelHeight:product.title labelFont:font textWidth:lbNameWidth].height; return width + 50 +lbNameHeight; } @end