YMPersonalPageGiftWallCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // YMPersonalPageGiftWallCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/14.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMPersonalPageGiftWallCell.h"
  9. #import "YMPersonalPageGiftWallCellViewModel.h"
  10. @interface YMPersonalPageGiftWallCell()
  11. /// ViewModel
  12. @property (nonatomic, strong) YMPersonalPageGiftWallCellViewModel *viewModel;
  13. /// 基础视图
  14. @property (nonatomic, strong) UIView *baseView;
  15. /// 礼物图标
  16. @property (nonatomic, strong) UIImageView *giftIcon;
  17. /// 礼物名标签
  18. @property (nonatomic, strong) UILabel *giftNameLb;
  19. /// 礼物数量标签
  20. @property (nonatomic, strong) UILabel *giftNumberLb;
  21. @end
  22. @implementation YMPersonalPageGiftWallCell
  23. - (void)ym_setupViews{
  24. [self.contentView addSubview:self.baseView];
  25. [self.baseView addSubview:self.giftIcon];
  26. [self.baseView addSubview:self.giftNameLb];
  27. [self.baseView addSubview:self.giftNumberLb];
  28. [self setNeedsUpdateConstraints];
  29. [self updateConstraintsIfNeeded];
  30. }
  31. - (void)updateConstraints {
  32. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.equalTo(self.contentView);
  34. make.left.equalTo(self.contentView);
  35. make.right.equalTo(self.contentView);
  36. make.bottom.equalTo(self.contentView);
  37. }];
  38. [self.giftIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.centerX.equalTo(self.baseView.mas_centerX);
  40. make.top.equalTo(self.baseView);
  41. make.width.height.mas_equalTo(adapt(60));
  42. }];
  43. [self.giftNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.giftIcon.mas_bottom).offset(adapt(5));
  45. make.left.equalTo(self.baseView);
  46. make.right.equalTo(self.baseView);
  47. }];
  48. [self.giftNumberLb mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.giftNameLb.mas_bottom).offset(adapt(5));
  50. make.left.equalTo(self.baseView);
  51. make.right.equalTo(self.baseView);
  52. make.bottom.equalTo(self.baseView);
  53. }];
  54. [super updateConstraints];
  55. }
  56. - (void)ym_bindViewModel:(YMPersonalPageGiftWallCellViewModel*)viewModel{
  57. if (!viewModel) {
  58. return;
  59. }
  60. _viewModel = viewModel;
  61. [self.giftIcon sd_setImageWithURL:[LCTools getImageUrlWithAddress:viewModel.giftIcon]];
  62. self.giftNameLb.text = viewModel.giftName;
  63. self.giftNumberLb.text = viewModel.giftNumber;
  64. }
  65. - (UIView *)baseView{
  66. if (!_baseView) {
  67. _baseView = [[UIView alloc]init];
  68. _baseView.clipsToBounds = YES;
  69. _baseView.layer.cornerRadius = adapt(8);
  70. }
  71. return _baseView;
  72. }
  73. - (UIImageView *)giftIcon{
  74. if (!_giftIcon) {
  75. _giftIcon = [[UIImageView alloc]init];
  76. _giftIcon.contentMode = UIViewContentModeScaleAspectFill;
  77. }
  78. return _giftIcon;
  79. }
  80. - (UILabel *)giftNameLb{
  81. if (!_giftNameLb) {
  82. _giftNameLb = [[UILabel alloc]init];
  83. _giftNameLb.font = LCFont(12);
  84. _giftNameLb.textColor = HexColorFromRGB(0x737373);
  85. _giftNameLb.textAlignment = NSTextAlignmentCenter;
  86. _giftNameLb.text = @"****";
  87. }
  88. return _giftNameLb;
  89. }
  90. - (UILabel *)giftNumberLb{
  91. if (!_giftNumberLb) {
  92. _giftNumberLb = [[UILabel alloc]init];
  93. _giftNumberLb.font = LCFont(12);
  94. _giftNumberLb.textColor = HexColorFromRGB(0x333333);
  95. _giftNumberLb.textAlignment = NSTextAlignmentCenter;
  96. _giftNumberLb.text = @"****";
  97. }
  98. return _giftNumberLb;
  99. }
  100. @end