YOUPAILZSessionUserInfoCell.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // YOUPAILZSessionUserInfoCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/3/8.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZSessionUserInfoCell.h"
  9. #import "YOUPAILZUserFeatureView.h"
  10. @interface YOUPAILZSessionUserInfoCell ()
  11. @property (nonatomic, weak) UIImageView *youpaipavatarImgV;
  12. @property (nonatomic, weak) UILabel *youpaipnicknameL;
  13. @property (nonatomic, weak) UILabel *youpaipcityL;
  14. @property (nonatomic, weak) UILabel *youpaipsignL;
  15. @property (nonatomic, weak) UIView *youpaipfeatureBgV; //特征背景
  16. @property (nonatomic, strong) NSMutableArray <YOUPAILZUserFeatureView *> *youpaipfeatureItems;
  17. @end
  18. @implementation YOUPAILZSessionUserInfoCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  20. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. [self youpaifinitUI];
  23. }
  24. return self;
  25. }
  26. - (void)youpaifinitUI{
  27. UIImageView *youpaipavatarImgV = [[UIImageView alloc] init];
  28. youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  29. youpaipavatarImgV.layer.cornerRadius = 10.0f;
  30. youpaipavatarImgV.clipsToBounds = YES;
  31. [self.contentView addSubview:youpaipavatarImgV];
  32. self.youpaipavatarImgV = youpaipavatarImgV;
  33. [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.offset(12.0f);
  35. make.top.offset(9.0f);
  36. make.size.mas_offset(CGSizeMake(63.0f, 63.0f));
  37. }];
  38. UILabel *youpaipnicknameL = [[UILabel alloc] init];
  39. youpaipnicknameL.textColor = LZ273145Color;
  40. youpaipnicknameL.font = LCFont(14.0f);
  41. [self.contentView addSubview:youpaipnicknameL];
  42. self.youpaipnicknameL = youpaipnicknameL;
  43. [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.equalTo(youpaipavatarImgV.mas_right).offset(10.0f);
  45. make.top.offset(9.0f);
  46. }];
  47. UILabel *youpaipcityL = [[UILabel alloc] init];
  48. youpaipcityL.textColor = LZA3AABEColor;
  49. youpaipcityL.font = LCFont(10.0f);
  50. [self.contentView addSubview:youpaipcityL];
  51. self.youpaipcityL = youpaipcityL;
  52. [youpaipcityL mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.equalTo(youpaipavatarImgV.mas_right).offset(10.0f);
  54. make.top.equalTo(youpaipnicknameL.mas_bottom).offset(8.0f);
  55. }];
  56. UILabel *youpaipsignL = [[UILabel alloc] init];
  57. youpaipsignL.textColor = LZA3AABEColor;
  58. youpaipsignL.font = LCFont(12.0f);
  59. youpaipsignL.numberOfLines = 2;
  60. [self.contentView addSubview:youpaipsignL];
  61. self.youpaipsignL = youpaipsignL;
  62. [youpaipsignL mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
  64. make.top.equalTo(youpaipcityL.mas_bottom).offset(8.0f);
  65. make.right.offset(-12.0f);
  66. }];
  67. UIView *youpaipfeatureBgV = [[UIView alloc] init];
  68. [self.contentView addSubview:youpaipfeatureBgV];
  69. self.youpaipfeatureBgV = youpaipfeatureBgV;
  70. [youpaipfeatureBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.equalTo(youpaipcityL.mas_right).offset(4.0f);
  72. make.height.offset(12.0f);
  73. make.centerY.equalTo(youpaipcityL);
  74. }];
  75. UIImageView *arrowImgView = [[UIImageView alloc]init];
  76. arrowImgView.contentMode = UIViewContentModeScaleAspectFill;
  77. arrowImgView.image = [UIImage imageNamed:@"vqu_images_H_cell_arrow_gray"];
  78. [self.contentView addSubview:arrowImgView];
  79. [arrowImgView makeConstraints:^(MASConstraintMaker *make) {
  80. make.right.equalTo(-12.0f);
  81. make.centerY.equalTo(youpaipcityL);
  82. make.size.mas_equalTo(CGSizeMake(10, 10));
  83. }];
  84. }
  85. - (void)youpaifreloadWithModel:(NSDictionary *)dict{
  86. [self.youpaipavatarImgV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:dict[@"avatar"]] urlWithImageScale:60]];
  87. self.youpaipnicknameL.text = dict[@"nickname"];
  88. self.youpaipcityL.text = dict[@"city"];
  89. self.youpaipsignL.text = dict[@"sign"];
  90. NSMutableArray *features = [NSMutableArray array];
  91. if ([dict[@"age"] integerValue] != 0) {
  92. [features addObject:[NSString stringWithFormat:@"%@岁", @([dict[@"age"] integerValue])]];
  93. }else{
  94. [features addObject:@"未知"];
  95. }
  96. if ([NSString stringWithFormat:@"%@",dict[@"height"]].length != 0) {
  97. [features addObject:dict[@"height"]];
  98. }else{
  99. [features addObject:@"未知"];
  100. }
  101. if ([NSString stringWithFormat:@"%@",dict[@"occupation"]].length != 0) {
  102. [features addObject:dict[@"occupation"]];
  103. }else{
  104. [features addObject:@"未知"];
  105. }
  106. [self youpaifeditBtnCountWithCount:features.count];
  107. YOUPAILZUserFeatureView *frontFeatureV = nil;
  108. for (NSInteger i = 0; i < self.youpaipfeatureItems.count; i ++) {
  109. YOUPAILZUserFeatureView *v = self.youpaipfeatureItems[i];
  110. [v youpaifreloadWithFeature:features[i]];
  111. [v mas_remakeConstraints:^(MASConstraintMaker *make) {
  112. if (frontFeatureV == nil) {
  113. make.left.offset(0.0f);
  114. }else{
  115. make.left.equalTo(frontFeatureV.mas_right).offset(4.0f);
  116. }
  117. make.top.bottom.offset(0.0f);
  118. if (i == self.youpaipfeatureItems.count - 1) {
  119. make.right.offset(0.0f);
  120. }
  121. }];
  122. frontFeatureV = v;
  123. }
  124. }
  125. - (void)youpaifeditBtnCountWithCount:(NSInteger)count{
  126. if (count >= self.youpaipfeatureItems.count) {
  127. [self youpaifaddBtnWithCount:count - self.youpaipfeatureItems.count];
  128. }else{
  129. [self youpaifdeleteBtnWithCount:self.youpaipfeatureItems.count - count];
  130. }
  131. }
  132. - (void)youpaifdeleteBtnWithCount:(NSInteger)count{
  133. if (count != 0) {
  134. for (NSInteger i = 0; i < count; i ++) {
  135. YOUPAILZUserFeatureView *v = self.youpaipfeatureItems.lastObject;
  136. [self.youpaipfeatureItems removeLastObject];
  137. [v removeFromSuperview];
  138. }
  139. }
  140. }
  141. - (void)youpaifaddBtnWithCount:(NSInteger)count{
  142. for (NSInteger i = 0; i < count; i ++) {
  143. [self youpaifcreateBtn];
  144. }
  145. }
  146. - (void)youpaifcreateBtn{
  147. YOUPAILZUserFeatureView *v = [[YOUPAILZUserFeatureView alloc] init];
  148. [self.youpaipfeatureBgV addSubview:v];
  149. [self.youpaipfeatureItems addObject:v];
  150. }
  151. - (NSMutableArray<YOUPAILZUserFeatureView *> *)youpaipfeatureItems{
  152. if (_youpaipfeatureItems == nil) {
  153. _youpaipfeatureItems = [NSMutableArray array];
  154. }
  155. return _youpaipfeatureItems;
  156. }
  157. @end