YOUPAIHRChatRoomHomeCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // YOUPAIHRChatRoomHomeCell.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/2.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomHomeCell.h"
  9. #import "YYAnimatedImageView.h"
  10. #import "YYImage.h"
  11. #import "LOTAnimationView.h"
  12. @interface YOUPAIHRChatRoomHomeCell ()
  13. @property (nonatomic,strong)UIImageView *youpaipimageV;//头像
  14. @property(nonatomic,strong)UILabel *youpaiptitleLabel;
  15. @property (nonatomic, weak) LOTAnimationView *youpaipiconAnimationImgV;
  16. @property (nonatomic, weak) UIButton *youpaiprightBottomBtn; // 右下角
  17. @property(nonatomic,strong)UIButton *youpaiphomeLockBtn;//房间锁
  18. @property(nonatomic ,strong)UILabel *youpaippeopleLabel;
  19. @property(nonatomic ,strong)UIView *youpaipfooterV;
  20. @property(nonatomic,strong)UIButton *youpaipmyHomeBtn;
  21. @property(nonatomic,strong)UIImageView *youpaipiconImageView;
  22. @property (nonatomic,strong)NSMutableArray <UIImageView *> *youpaipmemberAvatars;
  23. @property (nonatomic,weak)UIView *youpaipmemberAvatarBgV;
  24. @end
  25. @implementation YOUPAIHRChatRoomHomeCell
  26. -(instancetype)initWithFrame:(CGRect)frame{
  27. if (self = [super initWithFrame:frame]) {
  28. [self youpaifsetSubView];
  29. }
  30. return self;
  31. }
  32. -(void)youpaifsetSubView{
  33. // self.contentView.backgroundColor = [LCTools getBkgRandomColor];
  34. self.contentView.layer.cornerRadius = 5;
  35. self.contentView.layer.masksToBounds = YES;
  36. //头像
  37. UIImageView *iconImage = [[UIImageView alloc] init];
  38. [self.contentView addSubview:iconImage];
  39. self.youpaipimageV = iconImage;
  40. [self.youpaipimageV mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_equalTo(0);
  42. make.right.mas_equalTo(0);
  43. make.top.mas_equalTo(0);
  44. make.height.mas_equalTo(169);
  45. }];
  46. self.youpaipimageV.userInteractionEnabled = YES;
  47. self.youpaipimageV.layer.cornerRadius = 5;
  48. self.youpaipimageV.contentMode = UIViewContentModeScaleAspectFill;
  49. self.youpaipimageV.clipsToBounds = YES;
  50. //我的房间(类型,点唱,女神)
  51. UIButton *youpaipmyHomeBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 32, 18)];
  52. self.youpaipmyHomeBtn = youpaipmyHomeBtn;
  53. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomRight View:youpaipmyHomeBtn size:CGSizeMake(4, 4)];
  54. [self.youpaipimageV addSubview:youpaipmyHomeBtn];
  55. [youpaipmyHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  56. youpaipmyHomeBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  57. [youpaipmyHomeBtn setBackgroundColor:HexColorFromRGBA(0x000000, 0.38)];
  58. //房间锁
  59. UIButton *youpaiphomeLockBtn = [UIButton new];
  60. self.youpaiphomeLockBtn = youpaiphomeLockBtn;
  61. [self.youpaipimageV addSubview:youpaiphomeLockBtn];
  62. [youpaiphomeLockBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.right.mas_equalTo(0);
  64. make.top.mas_equalTo(0);
  65. make.size.mas_equalTo(CGSizeMake(35, 35));
  66. }];
  67. youpaiphomeLockBtn.hidden = YES;
  68. [youpaiphomeLockBtn setImage:[UIImage imageNamed:@"vqu_images_chatroom_lock"] forState:UIControlStateNormal];
  69. //阴影
  70. UIView *youpaipfooterV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.mj_w, 49.0f)];
  71. self.youpaipfooterV = youpaipfooterV;
  72. CAGradientLayer *gradientLayerBot = [LCTools getGradientLayerWithSize:youpaipfooterV.mj_size twoColors:@[[[UIColor blackColor] colorWithAlphaComponent:0.0f],[[UIColor blackColor] colorWithAlphaComponent:0.3f]] gradientType:GradientTopToBottom];
  73. [youpaipfooterV.layer addSublayer:gradientLayerBot];
  74. [self.youpaipimageV addSubview:youpaipfooterV];
  75. [youpaipfooterV mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.bottom.right.offset(0.0f);
  77. make.height.offset(34.0f);
  78. }];
  79. UIButton *youpaiprightBottomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  80. self.youpaiprightBottomBtn = youpaiprightBottomBtn;
  81. youpaiprightBottomBtn.frame = CGRectMake(0, 0, 56.0f, 20.0f);
  82. [LCTools clipCorner:UIRectCornerBottomRight View:youpaiprightBottomBtn size:CGSizeMake(8.0f, 8.0f)];
  83. [youpaipfooterV addSubview:youpaiprightBottomBtn];
  84. self.youpaiprightBottomBtn = youpaiprightBottomBtn;
  85. [youpaiprightBottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.right.offset(0.0f);
  87. make.centerY.mas_equalTo(0);
  88. make.size.mas_offset(CGSizeMake(56+5+4.5+20, 20.0f));
  89. }];
  90. //人数
  91. UILabel *youpaippeopleLabel = [UILabel new];
  92. self.youpaippeopleLabel = youpaippeopleLabel;
  93. [youpaipfooterV addSubview:youpaippeopleLabel];
  94. [youpaippeopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.right.mas_equalTo(-5);
  96. make.centerY.mas_equalTo(0);
  97. make.width.mas_equalTo(56+5);
  98. }];
  99. youpaippeopleLabel.textColor = [UIColor whiteColor];
  100. youpaippeopleLabel.font = [UIFont systemFontOfSize:12];
  101. //动画
  102. LOTAnimationView *youpaipiconAnimationImgV = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:@"ic_chatroom_part" ofType:@"json"]];
  103. [youpaiprightBottomBtn addSubview:youpaipiconAnimationImgV];
  104. // talkingAnimationView.frame = CGRectMake(0.0f, 0.0f, self.mj_w * 1.7f, self.mj_h * 1.7f);
  105. youpaipiconAnimationImgV.loopAnimation = YES;
  106. youpaipiconAnimationImgV.contentMode = UIViewContentModeScaleAspectFill;
  107. [youpaipiconAnimationImgV play];
  108. self.youpaipiconAnimationImgV = youpaipiconAnimationImgV;
  109. [youpaipiconAnimationImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.right.mas_equalTo(youpaippeopleLabel.mas_left).offset(-4.5);
  111. make.centerY.equalTo(youpaippeopleLabel).offset(-2);
  112. make.size.mas_offset(CGSizeMake(16.0f, 14.0f));
  113. }];
  114. //bottomView
  115. UIView *bottomView = [UIView new];
  116. [self.contentView addSubview:bottomView];
  117. [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.mas_equalTo(0);
  119. make.right.mas_equalTo(0);
  120. make.top.mas_equalTo(iconImage.mas_bottom);
  121. make.bottom.mas_equalTo(0);
  122. }];
  123. bottomView.backgroundColor = LCBkgColor;
  124. //title
  125. UILabel *titleLabel = [UILabel new];
  126. self.youpaiptitleLabel = titleLabel;
  127. [bottomView addSubview:titleLabel];
  128. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.mas_equalTo(5);
  130. make.right.mas_equalTo(0);
  131. make.centerY.mas_equalTo(0);
  132. }];
  133. titleLabel.text = @"快来签收你的小可爱";
  134. titleLabel.textColor = [UIColor whiteColor];
  135. titleLabel.font = [UIFont systemFontOfSize:14];
  136. //3个头像
  137. UIButton *threeIconBgBtn = [UIButton new];
  138. [youpaipfooterV addSubview:threeIconBgBtn];
  139. [threeIconBgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.left.mas_equalTo(0);
  141. make.top.mas_equalTo(0);
  142. make.width.mas_equalTo(49+24);
  143. }];
  144. UIView *youpaipmemberAvatarBgV = [[UIView alloc] init];
  145. [threeIconBgBtn addSubview:youpaipmemberAvatarBgV];
  146. self.youpaipmemberAvatarBgV = youpaipmemberAvatarBgV;
  147. [youpaipmemberAvatarBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.left.mas_equalTo(14);
  149. make.centerY.mas_equalTo(0);
  150. make.width.offset(0.0f);
  151. make.height.offset(24.0f);
  152. }];
  153. }
  154. - (void)setYoupaiphomeListModel:(YOUPAIHRChatRoomSubDetailModel *)youpaiphomeListModel{
  155. _youpaiphomeListModel = youpaiphomeListModel;
  156. CGFloat width = 0;
  157. if ([NSString stringWithFormat:@"%ld",youpaiphomeListModel.youpaipscores].length>5) {
  158. width = [LCTools widthWithString:[NSString stringWithFormat:@"%@",@"12345"] withFont:[UIFont systemFontOfSize:12]];
  159. }else{
  160. width = [LCTools widthWithString:[NSString stringWithFormat:@"%ld",youpaiphomeListModel.youpaipscores] withFont:[UIFont systemFontOfSize:12]];
  161. }
  162. [self.youpaiprightBottomBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  163. make.right.offset(0.0f);
  164. make.centerY.mas_equalTo(0);
  165. make.size.mas_offset(CGSizeMake(width+5+4.5+20, 20.0f));
  166. }];
  167. [self.youpaippeopleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  168. make.right.mas_equalTo(-5);
  169. make.centerY.mas_equalTo(0);
  170. make.width.mas_equalTo(width+5);
  171. }];
  172. [self youpaifeditBtnCountWithCount:youpaiphomeListModel.youpaipimg.count > 3 ? 3 : youpaiphomeListModel.youpaipimg.count];
  173. [self.youpaipmemberAvatarBgV updateConstraints:^(MASConstraintMaker *make) {
  174. make.width.offset(self.youpaipmemberAvatars.count * 24.0f - (self.youpaipmemberAvatars.count - 1.0f) * 4.0f);
  175. }];
  176. for (NSInteger i = 0; i < self.youpaipmemberAvatars.count; i ++) {
  177. UIImageView *imgV = self.youpaipmemberAvatars[i];
  178. imgV.layer.cornerRadius = 12.0f;
  179. imgV.clipsToBounds = YES;
  180. imgV.layer.borderWidth = 0.5;
  181. imgV.layer.borderColor = HexColorFromRGBA(0xffffff, 0.5).CGColor;
  182. imgV.frame = CGRectMake(i * 24.0f - i * 4.0f, 0.0f, 24.0f, 24.0f);
  183. Image *url = youpaiphomeListModel.youpaipimg[i];
  184. [imgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:url.youpaipimg] placeholderImage:nil];;
  185. }
  186. [self.youpaipimageV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:youpaiphomeListModel.youpaipcover_img] urlWithImageScale:60] placeholderImage:nil];
  187. self.youpaiptitleLabel.text = youpaiphomeListModel.youpaiptitle;
  188. if ([youpaiphomeListModel.youpaippwd isEqualToString:@"1"]) {//0未上锁;1已上锁
  189. self.youpaiphomeLockBtn.hidden = NO;
  190. }else{
  191. self.youpaiphomeLockBtn.hidden = YES;
  192. }
  193. self.youpaippeopleLabel.text = [NSString stringWithFormat:@"%ld",youpaiphomeListModel.youpaipscores];
  194. [self.youpaipmyHomeBtn setTitle:youpaiphomeListModel.youpaiprooms_title forState:UIControlStateNormal];
  195. }
  196. /// 顶部榜单相关函数
  197. - (void)youpaifeditBtnCountWithCount:(NSInteger)count{
  198. if (count >= self.youpaipmemberAvatars.count) {
  199. [self youpaifaddBtnWithCount:count - self.youpaipmemberAvatars.count];
  200. }else{
  201. [self youpaifdeleteBtnWithCount:self.youpaipmemberAvatars.count - count];
  202. }
  203. }
  204. - (void)youpaifdeleteBtnWithCount:(NSInteger)count{
  205. if (count != 0) {
  206. for (NSInteger i = 0; i < count; i ++) {
  207. UIImageView *btn = self.youpaipmemberAvatars.lastObject;
  208. [self.youpaipmemberAvatars removeLastObject];
  209. [btn removeFromSuperview];
  210. }
  211. }
  212. }
  213. - (void)youpaifaddBtnWithCount:(NSInteger)count{
  214. for (NSInteger i = 0; i < count; i ++) {
  215. [self youpaifcreateBtn];
  216. }
  217. }
  218. - (void)youpaifcreateBtn{
  219. UIImageView *imgV = [[UIImageView alloc] init];
  220. imgV.contentMode = UIViewContentModeScaleAspectFill;
  221. [self.youpaipmemberAvatarBgV addSubview:imgV];
  222. [self.youpaipmemberAvatars addObject:imgV];
  223. }
  224. - (NSMutableArray<UIImageView *> *)youpaipmemberAvatars{
  225. if (_youpaipmemberAvatars == nil) {
  226. _youpaipmemberAvatars = [NSMutableArray array];
  227. }
  228. return _youpaipmemberAvatars;
  229. }
  230. @end