// // StudentDetailCommonHeaderView.m // LN_School // // Created by 张嵘 on 2019/7/25. // Copyright © 2019 Danson. All rights reserved. // #import "StudentDetailCommonHeaderView.h" #import "UIView+gesture.h" #import "StudentDetailCommonHeaderModel.h" @interface StudentDetailCommonHeaderView () @property (nonatomic, readwrite, strong) UIView *contentView; @property (nonatomic, readwrite, strong) UILabel *titleLabel; @property (nonatomic, readwrite, strong) UIImageView *titleIconImageView; @end @implementation StudentDetailCommonHeaderView #pragma mark - Life Cycle - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self addSubview:self.contentView]; [self.contentView addSubview:self.titleIconImageView]; [self.contentView addSubview:self.titleLabel]; } __weak typeof (self) weakS = self; [self.contentView addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) { [weakS clickSelf]; }]; return self; } - (void)layoutSubviews { [super layoutSubviews]; [_contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.mas_offset(0); make.size.mas_equalTo(CGSizeMake(self.bounds.size.width, self.bounds.size.height)); }]; [_titleIconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.contentView); make.left.mas_offset(16); make.size.mas_equalTo(CGSizeMake(5, self.bounds.size.height * 0.4)); }]; [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.contentView); make.left.mas_equalTo(_titleIconImageView.mas_right).mas_offset(8); make.size.mas_equalTo(CGSizeMake(self.bounds.size.width * 0.3, self.bounds.size.height)); }]; } #pragma mark - Private Functions - (void)updateSecVUI:(__kindof HDSectionModel *)model { StudentDetailCommonHeaderModel *headerModel = model.headerObj; _titleLabel.text = headerModel.title; } - (void)clickSelf { self.callback(self.hdSecModel); } #pragma mark - LazyLoad -(UIView *)contentView { if (!_contentView) { _contentView = [[UIView alloc] init]; _contentView.backgroundColor = UIColor.whiteColor; } return _contentView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [UILabel new]; _titleLabel.font = [UIFont systemFontOfSize:20]; _titleLabel.textColor = RQSubColor; _titleLabel.textAlignment = NSTextAlignmentLeft; } return _titleLabel; } - (UIImageView *)titleIconImageView { if (!_titleIconImageView) { _titleIconImageView = [[UIImageView alloc] init]; _titleIconImageView.backgroundColor = RQSubColor; _titleIconImageView.layer.cornerRadius = 2.5; _titleIconImageView.clipsToBounds = YES; } return _titleIconImageView; } @end