// // KDPLiveRightHeaderView.m // KuDianProject // // Created by admin on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPLiveRightHeaderView.h" @interface KDPLiveRightHeaderView () @property (nonatomic, strong) UIView *topHeaderView; @property (nonatomic, strong) UIView *goodView; @property (nonatomic, strong) UILabel *goodCountLabel; @property (nonatomic, strong) UILabel *orderCountLabel; @property (nonatomic, strong) UILabel *investLabel; @property (nonatomic, strong) UIButton *todayBtn; @end @implementation KDPLiveRightHeaderView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self setContentView]; } return self; } - (void)setContentView{ self.backgroundColor = [UIColor clearColor]; self.topHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 116)]; self.topHeaderView.backgroundColor = [UIColor whiteColor]; [self.topHeaderView addCornerRadiusByRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(6, 6)]; [self addSubview:self.topHeaderView]; self.goodView = [[UIView alloc] initWithFrame:CGRectMake(0, self.topHeaderView.bottom + 10, SCREEN_WIDTH-20, 43)]; self.goodView.backgroundColor = [UIColor whiteColor]; self.goodView.hidden = YES; [self addSubview:self.goodView]; UILabel *goodTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 14, SCREEN_WIDTH-20, 21)]; goodTitleLabel.textColor = [UIColor colorWithHex:0x333333]; goodTitleLabel.font = FONT_SYS(15); goodTitleLabel.text = @"商品列表"; [self.goodView addSubview:goodTitleLabel]; self.todayBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [self.todayBtn setTitle:@"今天" forState:UIControlStateNormal]; [self.todayBtn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal]; self.todayBtn.titleLabel.font = FONT_SYS(14); self.todayBtn.tag = 2000; [self.todayBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; self.todayBtn.showsTouchWhenHighlighted = NO; [self.topHeaderView addSubview:self.todayBtn]; UIButton *yestBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [yestBtn setTitle:@"昨天" forState:UIControlStateNormal]; [yestBtn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal]; yestBtn.titleLabel.font = FONT_SYS(14); yestBtn.tag = 2001; [yestBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; yestBtn.showsTouchWhenHighlighted = NO; [self.topHeaderView addSubview:yestBtn]; UIButton *totalBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [totalBtn setTitle:@"全部" forState:UIControlStateNormal]; [totalBtn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal]; totalBtn.titleLabel.font = FONT_SYS(14); totalBtn.tag = 2002; [totalBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; totalBtn.showsTouchWhenHighlighted = NO; [self.topHeaderView addSubview:totalBtn]; // 虚线 CAShapeLayer *dotteShapeLayer = [CAShapeLayer layer]; CGMutablePathRef dotteshapePath = CGPathCreateMutable(); // 设置虚线颜色 [dotteShapeLayer setStrokeColor:[UIColor colorWithHex:0xC5C5C5].CGColor]; dotteShapeLayer.lineWidth = 0.3f; NSArray *dottehShapeArr = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4], nil]; [dotteShapeLayer setLineDashPattern:dottehShapeArr]; CGPathMoveToPoint(dotteshapePath, NULL, 8,40); CGPathAddLineToPoint(dotteshapePath, NULL, self.topHeaderView.width-7, 40); [dotteShapeLayer setPath:dotteshapePath]; CGPathRelease(dotteshapePath); [self.topHeaderView.layer addSublayer:dotteShapeLayer]; self.goodCountLabel = [[UILabel alloc] init]; self.goodCountLabel.font = FONT_SYS(20); self.goodCountLabel.textAlignment = NSTextAlignmentCenter; self.goodCountLabel.textColor = [UIColor colorWithHex:0x333333]; self.goodCountLabel.text = @"0"; [self.topHeaderView addSubview:self.goodCountLabel]; UILabel *goodDetailLabel = [[UILabel alloc] init]; goodDetailLabel.textColor = [UIColor colorWithHex:0x666666]; goodDetailLabel.font = FONT_SYS(12); goodDetailLabel.textAlignment = NSTextAlignmentCenter; goodDetailLabel.text = @"上架商品数"; [self.topHeaderView addSubview:goodDetailLabel]; self.orderCountLabel = [[UILabel alloc] init]; self.orderCountLabel.font = FONT_SYS(20); self.orderCountLabel.textColor = [UIColor colorWithHex:0x333333]; self.orderCountLabel.text = @"0"; self.orderCountLabel.textAlignment = NSTextAlignmentCenter; [self.topHeaderView addSubview:self.orderCountLabel]; UILabel *orderDetailLabel = [[UILabel alloc] init]; orderDetailLabel.textColor = [UIColor colorWithHex:0x666666]; orderDetailLabel.font = FONT_SYS(12); orderDetailLabel.textAlignment = NSTextAlignmentCenter; orderDetailLabel.text = @"订单数"; [self.topHeaderView addSubview:orderDetailLabel]; self.investLabel = [[UILabel alloc] init]; self.investLabel.font = FONT_SYS(20); self.investLabel.textColor = [UIColor colorWithHex:0x333333]; self.investLabel.text = @"0"; self.investLabel.textAlignment = NSTextAlignmentCenter; [self.topHeaderView addSubview:self.investLabel]; UILabel *investDetailLabel = [[UILabel alloc] init]; investDetailLabel.textColor = [UIColor colorWithHex:0x666666]; investDetailLabel.font = FONT_SYS(12); investDetailLabel.textAlignment = NSTextAlignmentCenter; investDetailLabel.text = @"预估收益"; [self.topHeaderView addSubview:investDetailLabel]; [yestBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.size.equalTo(CGSizeMake(30, 20)); make.top.equalTo(self.topHeaderView.mas_top).offset(10); make.centerX.equalTo(self.topHeaderView); }]; [self.todayBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(yestBtn.mas_left).offset(-36); make.size.top.equalTo(yestBtn); }]; [totalBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(yestBtn.mas_right).offset(35); make.size.top.equalTo(yestBtn); }]; [self.orderCountLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(yestBtn.mas_bottom).offset(20); make.centerX.equalTo(self.topHeaderView); make.size.equalTo(CGSizeMake(80, 28)); }]; [orderDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.orderCountLabel.mas_bottom).offset(6); make.centerX.equalTo(self.orderCountLabel); make.size.equalTo(self.orderCountLabel); }]; [self.goodCountLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.orderCountLabel.mas_top); make.right.equalTo(self.orderCountLabel.mas_left).offset(-20); make.size.equalTo(self.orderCountLabel); }]; [goodDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.goodCountLabel.mas_bottom).offset(6); make.size.equalTo(self.goodCountLabel); make.right.equalTo(self.goodCountLabel); }]; [self.investLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.orderCountLabel); make.left.equalTo(self.orderCountLabel.mas_right).offset(20); make.size.equalTo(self.orderCountLabel); }]; [investDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.investLabel); make.size.equalTo(self.investLabel); make.top.equalTo(goodDetailLabel); }]; } - (void)setSelectIndex:(NSInteger)selectIndex{ _selectIndex = selectIndex; UIButton *button = [self.topHeaderView viewWithTag:2000+selectIndex]; [self buttonClick:button]; } - (void)reloadHeaderData:(NSDictionary *)dict{ if ([dict isEqual:[NSNull null]]) { return; } if ([dict valueForKey:@"goods_num"] != nil) { self.goodCountLabel.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"goods_num"]]; } if ([dict valueForKey:@"order_num"] != nil) { self.orderCountLabel.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"order_num"]]; } if ([dict valueForKey:@"total_rebate"] != nil) { self.investLabel.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"total_rebate"]]; } } - (void)setHiddenGoodTipView:(BOOL)hiddenGoodTipView{ _hiddenGoodTipView = hiddenGoodTipView; self.goodView.hidden = hiddenGoodTipView; } - (void)buttonClick:(UIButton *)sender{ NSInteger index = sender.tag - 2000; [self.topHeaderView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[UIButton class]]) { UIButton *button = (UIButton *)obj; [button setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal]; } }]; [UIView animateWithDuration:0.25 animations:^{ [sender setTitleColor:[UIColor baseColor] forState:UIControlStateNormal]; }]; if (self.clickBlock) { self.clickBlock(index); } } @end