//
//  HMNewsHeaderView.m
//  Open
//
//  Created by 雷俊博 on 2021/7/21.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "HMNewsHeaderView.h"
#import "GovLineView.h"

@implementation HMNewsHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //[self setupUI];
    }
    return self;
}

- (void)setupUI
{
    //新闻header
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 46 * WIDTHRADIU)];
    headerView.backgroundColor = [UIColor whiteColor];
    [self addSubview:headerView];
    
    
    //line
    GovLineView *lineView = [[GovLineView alloc]initWithFrame:CGRectMake(15 * WIDTHRADIU, 15 * WIDTHRADIU, 4, 16 * WIDTHRADIU)];
    [headerView addSubview:lineView];
    
    UILabel *lb_title = [UILabel new];
    lb_title.text = @"健康新闻";
    lb_title.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb_title.font = [UIFont systemFontOfSize:17 * WIDTHRADIU weight:UIFontWeightMedium];
    [headerView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lineView.mas_right).offset(10 * WIDTHRADIU);
        make.centerY.equalTo(lineView);
    }];
    
    //查看全部
    UILabel *checkLabel = [UILabel new];
    checkLabel.text = @"查看全部>>";
    checkLabel.textColor = [UIColor colorWithHex:0x808080];
    checkLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
    checkLabel.textAlignment = NSTextAlignmentRight;
    [headerView addSubview:checkLabel];
    
    [checkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15 * WIDTHRADIU);
        make.centerY.equalTo(headerView);
        make.height.offset(46 * WIDTHRADIU);
    }];
    
    UIButton *checkAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    checkAllBtn.tag = 200;
    [checkAllBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:checkAllBtn];
    [checkAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(checkLabel);
    }];
}

#pragma mark - event response
- (void)btnClick:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(HMNewsHeaderViewBtnClickWithIndex:)]) {
        [self.delegate HMNewsHeaderViewBtnClickWithIndex:sender.tag];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
