// // FKSubmitSingleChannelView.m // FirstLink // // Created by jack on 16/1/19. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKSubmitSingleChannelView.h" @interface FKSubmitSingleChannelView () @property (nonatomic, strong) UIImageView *iconImgView; @end @implementation FKSubmitSingleChannelView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self addAllSubviews]; } return self; } - (void)addAllSubviews{ [self addSubview:self.iconImgView]; [self addSubview:self.channelLabel]; [self addSubview:self.ruleLabel]; [self addSubview:self.priceLabel]; [self addSubview:self.billWightLabel]; [self addSubview:self.bottomLine]; [self addSubview:self.clickActionBtn]; [self addSubview:self.arrowBtn]; [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(10); make.centerY.equalTo(self.mas_top).offset(34.5); }]; [self.channelLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.mas_top).offset(29.5); make.left.equalTo(self.iconImgView.mas_right).offset(10); make.right.equalTo(self.priceLabel.mas_left).offset(- 5); }]; [self.ruleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.mas_top).offset(39.5); make.left.equalTo(self.channelLabel); make.right.equalTo(self).offset(- 10); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.channelLabel); make.right.equalTo(self).offset(- 5); }]; // [self.priceCutLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.equalTo(self).offset(- 5); // make.top.equalTo(self).offset(39.5); // }]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(10); make.right.equalTo(self).offset(- 10); make.bottom.equalTo(self); make.height.mas_equalTo(0.5); }]; [self.billWightLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self); make.top.equalTo(self.ruleLabel.mas_bottom); make.right.equalTo(self.priceLabel); }]; [self.clickActionBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.insets(UIEdgeInsetsMake(0, 0, 0, - 50)); }]; [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.ruleLabel); make.right.equalTo(self); make.size.mas_equalTo(CGSizeMake(45, 50)); }]; } - (void)resetContentForChannelItem:(FKTransformChannelItem *)channelItem enable:(BOOL)enable billWeight:(NSString *)billWeight { if (!channelItem) return; self.channelType = channelItem.channelType; self.channelLabel.text = channelItem.name; self.ruleLabel.text = channelItem.postageRule; self.priceLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:channelItem.price]]; if (!enable) { // 不可选 self.channelLabel.textColor = UIColorFromRGB(0xcccccc); self.ruleLabel.textColor = UIColorFromRGB(0xcccccc); self.priceLabel.textColor = UIColorFromRGB(0xcccccc); self.iconImgView.hidden = YES; self.clickActionBtn.userInteractionEnabled = NO; }else{ self.iconImgView.hidden = NO; self.clickActionBtn.userInteractionEnabled = YES; self.channelLabel.textColor = UIColorFromRGB(0x333333); self.ruleLabel.textColor = UIColorFromRGB(0x999999); self.priceLabel.textColor = UIColorFromRGB(0x999999); } if (channelItem.selected) { self.iconImgView.image = [UIImage imageNamed:@"submit_channel_chose_h"]; }else{ self.iconImgView.image = [UIImage imageNamed:@"basket_unSelect"]; } if (billWeight) { self.billWightLabel.hidden = NO; self.billWightLabel.text = billWeight; } else{ self.billWightLabel.text = nil; self.billWightLabel.hidden = YES; } } #pragma mark - property - (UIImageView *)iconImgView{ if (_iconImgView == nil) { _iconImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"submit_channel_chose_n"]]; [_iconImgView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; [_iconImgView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } return _iconImgView; } - (UILabel *)channelLabel{ if (_channelLabel == nil) { _channelLabel = [[UILabel alloc]init]; _channelLabel.textColor = UIColorFromRGB(0x333333); _channelLabel.font = [UIFont systemFontOfSize:14]; _channelLabel.lineBreakMode = NSLineBreakByTruncatingTail; } return _channelLabel; } - (UILabel *)ruleLabel{ if (_ruleLabel == nil) { _ruleLabel = [[UILabel alloc]init]; _ruleLabel.textColor = UIColorFromRGB(0x666666); _ruleLabel.font = [UIFont systemFontOfSize:12]; } return _ruleLabel; } - (UILabel *)priceLabel{ if (_priceLabel == nil) { _priceLabel = [[UILabel alloc]init]; _priceLabel.textColor = UIColorFromRGB(0x333333); _priceLabel.font = [UIFont systemFontOfSize:14]; [_priceLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; [_priceLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } return _priceLabel; } //- (UILabel *)priceCutLabel{ // if (_priceCutLabel == nil) { // _priceCutLabel = [[UILabel alloc]init]; // _priceCutLabel.textColor = UIColorFromRGB(0xff624a); // _priceCutLabel.font = [UIFont systemFontOfSize:12]; // if (UISCREENWIDTH <= 320) _priceCutLabel.font = [UIFont systemFontOfSize:11]; // 适配45 // [_priceCutLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; // [_priceCutLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; // } // return _priceCutLabel; //} - (UIView *)bottomLine{ if (_bottomLine == nil) { _bottomLine = [[UIView alloc]init]; _bottomLine.backgroundColor = UIColorFromRGB(0xcccccc); } return _bottomLine; } - (UIButton *)clickActionBtn{ if (_clickActionBtn == nil) { _clickActionBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _clickActionBtn; } - (UIButton *)arrowBtn{ if (_arrowBtn == nil) { _arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_arrowBtn setImage:[UIImage imageNamed:@"submit_arrow_down"] forState:UIControlStateNormal]; [_arrowBtn setImage:[UIImage imageNamed:@"submit_arrow_up"] forState:UIControlStateSelected]; } return _arrowBtn; } - (UILabel *)billWightLabel{ if (_billWightLabel == nil) { _billWightLabel = [[UILabel alloc]init]; _billWightLabel.font = [UIFont systemFontOfSize:11]; _billWightLabel.textColor = UIColorFromRGB(0x666666); _billWightLabel.textAlignment = NSTextAlignmentCenter; } return _billWightLabel; } @end