HomePageSecOneCell.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // HomePageSecOneCell.m
  3. // LN_School
  4. //
  5. // Created by 张嵘 on 2019/7/9.
  6. // Copyright © 2019 Danson. All rights reserved.
  7. //
  8. #import "HomePageSecOneCell.h"
  9. #import "UIView+gesture.h"
  10. #import "HomePageSecOneModel.h"
  11. @interface HomePageSecOneCell ()
  12. @property (nonatomic, readwrite, strong) UILabel *titleLabel;
  13. @property (nonatomic, readwrite, strong) UIImageView *imageView;
  14. @end
  15. @implementation HomePageSecOneCell
  16. #pragma mark - Life Cycle
  17. - (instancetype)initWithFrame:(CGRect)frame {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.contentView.backgroundColor = UIColor.whiteColor;
  21. [self.contentView addSubview:self.imageView];
  22. [self.contentView addSubview:self.titleLabel];
  23. }
  24. __weak typeof(self) weakS = self;
  25. [self addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
  26. [weakS clickSelf];
  27. }];
  28. return self;
  29. }
  30. - (void)layoutSubviews {
  31. [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.centerX.mas_equalTo(self.contentView);
  33. make.centerY.mas_equalTo(self.contentView).mas_offset(-10);
  34. make.height.width.mas_equalTo(self.bounds.size.width *0.5);
  35. }];
  36. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(0);
  38. make.centerX.mas_equalTo(self.contentView);
  39. make.height.mas_equalTo(self.bounds.size.width *0.33);
  40. }];
  41. [super layoutSubviews];
  42. }
  43. #pragma mark - Private Functions
  44. - (void)updateCellUI:(__kindof HDCellModel *)model {
  45. if ([model.orgData isKindOfClass:[HomePageSecOneModel class]]) {
  46. HomePageSecOneModel *homePageSecOneModel = model.orgData;
  47. self.titleLabel.text = homePageSecOneModel.title;
  48. self.imageView.image = [UIImage imageNamed:homePageSecOneModel.imageName];
  49. }
  50. }
  51. - (void)clickSelf {
  52. self.callback(self.hdModel);
  53. }
  54. #pragma mark - Lazy Load
  55. - (UILabel *)titleLabel {
  56. if (!_titleLabel) {
  57. _titleLabel = [[UILabel alloc] init];
  58. _titleLabel.textAlignment = NSTextAlignmentCenter;
  59. _titleLabel.numberOfLines = 0;
  60. _titleLabel.font = [UIFont systemFontOfSize:14];
  61. _titleLabel.textColor = RQTitleTextColor;
  62. }
  63. return _titleLabel;
  64. }
  65. - (UIImageView *)imageView {
  66. if (!_imageView) {
  67. _imageView = [[UIImageView alloc] init];
  68. }
  69. return _imageView;
  70. }
  71. @end