StudentDetailCommonHeaderView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // StudentDetailCommonHeaderView.m
  3. // LN_School
  4. //
  5. // Created by 张嵘 on 2019/7/25.
  6. // Copyright © 2019 Danson. All rights reserved.
  7. //
  8. #import "StudentDetailCommonHeaderView.h"
  9. #import "UIView+gesture.h"
  10. #import "StudentDetailCommonHeaderModel.h"
  11. @interface StudentDetailCommonHeaderView ()
  12. @property (nonatomic, readwrite, strong) UIView *contentView;
  13. @property (nonatomic, readwrite, strong) UILabel *titleLabel;
  14. @property (nonatomic, readwrite, strong) UIImageView *titleIconImageView;
  15. @end
  16. @implementation StudentDetailCommonHeaderView
  17. #pragma mark - Life Cycle
  18. - (instancetype)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self addSubview:self.contentView];
  22. [self.contentView addSubview:self.titleIconImageView];
  23. [self.contentView addSubview:self.titleLabel];
  24. }
  25. __weak typeof (self) weakS = self;
  26. [self.contentView addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
  27. [weakS clickSelf];
  28. }];
  29. return self;
  30. }
  31. - (void)layoutSubviews {
  32. [super layoutSubviews];
  33. [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.top.right.mas_offset(0);
  35. make.size.mas_equalTo(CGSizeMake(self.bounds.size.width, self.bounds.size.height));
  36. }];
  37. [_titleIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.centerY.mas_equalTo(self.contentView);
  39. make.left.mas_offset(16);
  40. make.size.mas_equalTo(CGSizeMake(5, self.bounds.size.height * 0.4));
  41. }];
  42. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.centerY.mas_equalTo(self.contentView);
  44. make.left.mas_equalTo(_titleIconImageView.mas_right).mas_offset(8);
  45. make.size.mas_equalTo(CGSizeMake(self.bounds.size.width * 0.3, self.bounds.size.height));
  46. }];
  47. }
  48. #pragma mark - Private Functions
  49. - (void)updateSecVUI:(__kindof HDSectionModel *)model {
  50. StudentDetailCommonHeaderModel *headerModel = model.headerObj;
  51. _titleLabel.text = headerModel.title;
  52. }
  53. - (void)clickSelf {
  54. self.callback(self.hdSecModel);
  55. }
  56. #pragma mark - LazyLoad
  57. -(UIView *)contentView {
  58. if (!_contentView) {
  59. _contentView = [[UIView alloc] init];
  60. _contentView.backgroundColor = UIColor.whiteColor;
  61. }
  62. return _contentView;
  63. }
  64. - (UILabel *)titleLabel {
  65. if (!_titleLabel) {
  66. _titleLabel = [UILabel new];
  67. _titleLabel.font = [UIFont systemFontOfSize:20];
  68. _titleLabel.textColor = RQSubColor;
  69. _titleLabel.textAlignment = NSTextAlignmentLeft;
  70. }
  71. return _titleLabel;
  72. }
  73. - (UIImageView *)titleIconImageView {
  74. if (!_titleIconImageView) {
  75. _titleIconImageView = [[UIImageView alloc] init];
  76. _titleIconImageView.backgroundColor = RQSubColor;
  77. _titleIconImageView.layer.cornerRadius = 2.5;
  78. _titleIconImageView.clipsToBounds = YES;
  79. }
  80. return _titleIconImageView;
  81. }
  82. @end