YMCallRecordCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // YMCallRecordCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/20.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCallRecordCell.h"
  9. #import "YMCallRecordCellViewModel.h"
  10. @interface YMCallRecordCell ()
  11. /// 通话记录VM
  12. @property (nonatomic, strong) YMCallRecordCellViewModel *viewModel;
  13. /// 基础视图
  14. @property (nonatomic, strong) UIView *baseView;
  15. /// 用户头像视图
  16. @property (nonatomic, strong) UIImageView *userAvatarView;
  17. /// 用户昵称标签
  18. @property (nonatomic, strong) UILabel *userNicknameLb;
  19. /// 用户通话时长标签
  20. @property (nonatomic, strong) UILabel *userCallDurationLb;
  21. /// 用户通话日期标签
  22. @property (nonatomic, strong) UILabel *userCallDateLb;
  23. @end
  24. @implementation YMCallRecordCell
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. // Initialization code
  28. }
  29. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  30. [super setSelected:selected animated:animated];
  31. // Configure the view for the selected state
  32. }
  33. - (void)ym_setupViews{
  34. [self.contentView addSubview:self.baseView];
  35. [self.baseView addSubview:self.userAvatarView];
  36. [self.baseView addSubview:self.userNicknameLb];
  37. [self.baseView addSubview:self.userCallDurationLb];
  38. [self.baseView addSubview:self.userCallDateLb];
  39. [self setNeedsUpdateConstraints];
  40. [self updateConstraintsIfNeeded];
  41. }
  42. - (void)updateConstraints{
  43. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.contentView);
  45. make.left.equalTo(self.contentView);
  46. make.right.equalTo(self.contentView);
  47. make.bottom.equalTo(self.contentView);
  48. }];
  49. [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerY.equalTo(self.baseView.mas_centerY);
  51. make.left.equalTo(self.baseView).offset(adapt(15));
  52. make.width.height.mas_equalTo(adapt(50));
  53. }];
  54. [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(5));
  56. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  57. }];
  58. [self.userCallDurationLb mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.bottom.equalTo(self.userAvatarView.mas_bottom).offset(adapt(-5));
  60. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  61. }];
  62. [self.userCallDateLb mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.centerY.equalTo(self.baseView.mas_centerY);
  64. make.right.equalTo(self.baseView).offset(adapt(-15));
  65. }];
  66. [super updateConstraints];
  67. }
  68. - (void)ym_bindViewModel:(YMCallRecordCellViewModel *)viewModel{
  69. if (!viewModel) {
  70. return;
  71. }
  72. _viewModel = viewModel;
  73. self.userNicknameLb.text = self.viewModel.userNickname;
  74. [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]];
  75. self.userCallDurationLb.text = self.viewModel.userCallDuration;
  76. self.userCallDateLb.text = self.viewModel.userCallDate;
  77. }
  78. - (UIView *)baseView{
  79. if (!_baseView) {
  80. _baseView = [[UIView alloc]init];
  81. }
  82. return _baseView;
  83. }
  84. - (UIImageView *)userAvatarView{
  85. if (!_userAvatarView) {
  86. _userAvatarView = [[UIImageView alloc]init];
  87. _userAvatarView.backgroundColor = UIColor.lightGrayColor;
  88. _userAvatarView.layer.cornerRadius = adapt(50)/2;
  89. _userAvatarView.layer.masksToBounds = YES;
  90. }
  91. return _userAvatarView;
  92. }
  93. - (UILabel *)userNicknameLb{
  94. if (!_userNicknameLb) {
  95. _userNicknameLb = [[UILabel alloc]init];
  96. _userNicknameLb.font = LCBoldFont(15);
  97. _userNicknameLb.textColor = HexColorFromRGB(0x1B2739);
  98. _userNicknameLb.textAlignment = NSTextAlignmentLeft;
  99. _userNicknameLb.text = @"******";
  100. }
  101. return _userNicknameLb;
  102. }
  103. - (UILabel *)userCallDurationLb{
  104. if (!_userCallDurationLb) {
  105. _userCallDurationLb = [[UILabel alloc]init];
  106. _userCallDurationLb.font = LCFont(12);
  107. _userCallDurationLb.textColor = HexColorFromRGB(0x7E848D);
  108. _userCallDurationLb.textAlignment = NSTextAlignmentLeft;
  109. _userCallDurationLb.text = @"通话时长:**:**";
  110. }
  111. return _userCallDurationLb;
  112. }
  113. - (UILabel *)userCallDateLb{
  114. if (!_userCallDateLb) {
  115. _userCallDateLb = [[UILabel alloc]init];
  116. _userCallDateLb.font = LCFont(12);
  117. _userCallDateLb.textColor = HexColorFromRGB(0x7E848D);
  118. _userCallDateLb.textAlignment = NSTextAlignmentLeft;
  119. _userCallDateLb.text = @"****.**.**";
  120. }
  121. return _userCallDateLb;
  122. }
  123. @end