HomePageSectionThreeHeaderView.m 3.9 KB

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