ShowPhotoesCell.m 2.2 KB

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