// // HCGoodDetailBottomView.m // hc // // Created by xiaoxi on 2018/1/25. // Copyright © 2018年 hc. All rights reserved. // #import "HCGoodDetailBottomView.h" #import "HCGoodDetailModel.h" @interface HCGoodDetailBottomView () @end @implementation HCGoodDetailBottomView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } - (void)initSubviews { [self addSubview:self.collectButton]; [self addSubview:self.buyButton]; // [self addSubview:self.commissionButton]; [self.collectButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(0); make.width.mas_equalTo(Fitsize(96)); make.bottom.mas_equalTo(0); }]; // [self.commissionButton mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(self.collectButton.mas_right); // make.top.bottom.mas_equalTo(0); // make.width.mas_equalTo((SCREEN_WIDTH-Fitsize(96))/2); // }]; [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.collectButton.mas_right); make.top.bottom.mas_equalTo(0); make.right.mas_equalTo(0); }]; } - (void)setGoodModel:(HCGoodDetailModel *)goodModel { _goodModel = goodModel; if ([goodModel.is_favorites isEqual:@1]) { self.collectButton.selected = YES; } else { self.collectButton.selected = NO; } [_commissionButton setTitle:@"马上分享" forState:UIControlStateNormal]; _commissionButton.hidden=YES; [_buyButton setTitle:@"立即购买" forState:UIControlStateNormal]; } - (void)buttonAction:(UIButton *)sender { // switch (sender.tag) { case 1: { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailBottomViewClickCollectButton)]) { [self.delegate yh_GoodDetailBottomViewClickCollectButton]; } } break; case 2: { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailBottomViewClickCommissionButton)]) { [self.delegate yh_GoodDetailBottomViewClickCommissionButton]; } } break; case 3: { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailBottomViewClickBuyButton)]) { [self.delegate yh_GoodDetailBottomViewClickBuyButton]; } } break; default: break; } } #pragma mark - lazy - (UIButton *)shopButton { if (!_shopButton) { _shopButton = [UIButton buttonWithType:UIButtonTypeCustom]; _shopButton.backgroundColor = [UIColor clearColor]; [_shopButton setTitleColor:[UIColor YHColorWithHex:0x444444] forState:UIControlStateNormal]; _shopButton.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(10)]; [_shopButton setTitle:@"店铺" forState:UIControlStateNormal]; [_shopButton setImage:[UIImage imageNamed:@"detail_shop"] forState:UIControlStateNormal]; [_shopButton setButtonStyle:WSLButtonStyleImageTop spacing:5]; _shopButton.tag = 1; [_shopButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _shopButton; } - (UIButton *)collectButton { if (!_collectButton) { _collectButton = [UIButton buttonWithType:UIButtonTypeCustom]; _collectButton.backgroundColor = [UIColor clearColor]; [_collectButton setTitleColor:[UIColor YHColorWithHex:0x444444] forState:UIControlStateNormal]; _collectButton.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(10)]; [_collectButton setTitle:@"收藏" forState:UIControlStateNormal]; [_collectButton setImage:[UIImage imageNamed:@"detail_collect"] forState:UIControlStateNormal]; [_collectButton setImage:[UIImage imageNamed:@"detail_collect_selected"] forState:UIControlStateSelected]; [_collectButton setButtonStyle:WSLButtonStyleImageTop spacing:5]; _collectButton.tag = 1; [_collectButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _collectButton; } - (UIButton *)buyButton { if (!_buyButton) { _buyButton = [UIButton buttonWithType:UIButtonTypeCustom]; _buyButton.backgroundColor = [UIColor homeRedColor]; _buyButton.titleLabel.numberOfLines = 1; _buyButton.titleLabel.textAlignment = NSTextAlignmentCenter; _buyButton.tag = 3; [_buyButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; _buyButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [_buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } return _buyButton; } - (UIButton *)commissionButton { if (!_commissionButton) { _commissionButton = [UIButton buttonWithType:UIButtonTypeCustom]; _commissionButton.backgroundColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFEC800] toColor:[UIColor YHColorWithHex:0xFD9D03] withWidth:(SCREEN_WIDTH-Fitsize(90))/2]; _commissionButton.titleLabel.textAlignment = NSTextAlignmentCenter; _commissionButton.tag = 2; [_commissionButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; _commissionButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [_commissionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } return _commissionButton; } @end