YOUPAILZHomeActiveCell.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. //
  2. // YOUPAILZHomeActiveCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/2/28.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZHomeActiveCell.h"
  9. #import "YOUPAILZUserFeatureView.h"
  10. @interface YOUPAILZHomeActiveCell ()
  11. @property (nonatomic, weak) UIImageView *youpaipavatarImgV; // 头像
  12. @property (nonatomic, weak) UIImageView *youpaipnewUserImgV; // 新人
  13. @property (nonatomic, weak) UIView *youpaiponlineStateV; // 在线状态
  14. @property (nonatomic, weak) UILabel *youpaipnicknameL; // 昵称
  15. @property (nonatomic, weak) UIImageView *youpaipimmortalImgV; // 真人
  16. @property (nonatomic, weak) UIImageView *youpaipvipImgV; // vip
  17. @property (nonatomic, weak) UILabel *youpaipcityL; // 城市
  18. @property (nonatomic, weak) UILabel *youpaipsignL; // 个性签名
  19. @property (nonatomic, weak) UIButton *youpaipAudioBtn; // 声音展示
  20. @property (nonatomic, weak) UILabel *youpaipAudioL; // 声音时长
  21. @property (nonatomic, weak) UIButton *youpaipchatBtn; // 私信
  22. @property (nonatomic, weak) UIView *youpaipfeatureBgV; //特征背景
  23. @property (nonatomic, strong) NSMutableArray <YOUPAILZUserFeatureView *> *youpaipfeatureItems;
  24. @property (nonatomic, strong) YOUPAILCHomeListModel *model;
  25. @end
  26. @implementation YOUPAILZHomeActiveCell
  27. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  28. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  29. self.selectionStyle = UITableViewCellSelectionStyleNone;
  30. self.backgroundColor = [UIColor clearColor];
  31. [self youpaifinitUI];
  32. }
  33. return self;
  34. }
  35. - (void)youpaifinitUI{
  36. UIView *bgV = [[UIView alloc] init];
  37. bgV.layer.cornerRadius = 10.0f;
  38. bgV.clipsToBounds = YES;
  39. bgV.backgroundColor = [UIColor whiteColor];
  40. [self.contentView addSubview:bgV];
  41. UIImageView *youpaipavatarImgV = [[UIImageView alloc] init];
  42. youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  43. youpaipavatarImgV.layer.cornerRadius = 10.0f;
  44. youpaipavatarImgV.clipsToBounds = YES;
  45. [self.contentView addSubview:youpaipavatarImgV];
  46. self.youpaipavatarImgV = youpaipavatarImgV;
  47. [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.offset(12.0f);
  49. make.centerY.equalTo(self.contentView);
  50. make.size.mas_offset(CGSizeMake(70.0f, 70.0f));
  51. }];
  52. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.equalTo(youpaipavatarImgV.mas_left).offset(14.0f);
  54. make.top.bottom.offset(0.0f);
  55. make.right.offset(-12.0f);
  56. }];
  57. UIImageView *youpaipnewUserImgV = [[UIImageView alloc] init];
  58. youpaipnewUserImgV.image = [UIImage imageNamed:@"vqu_images_home_new_user"];
  59. youpaipnewUserImgV.hidden = YES;
  60. [youpaipavatarImgV addSubview:youpaipnewUserImgV];
  61. self.youpaipnewUserImgV = youpaipnewUserImgV;
  62. [youpaipnewUserImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.top.offset(0.0f);
  64. make.size.mas_offset(CGSizeMake(26.0f, 13.0f));
  65. }];
  66. UIView *youpaiponlineStateV = [[UIView alloc] init];
  67. youpaiponlineStateV.layer.cornerRadius = 6.0f;
  68. youpaiponlineStateV.layer.borderColor = [UIColor whiteColor].CGColor;
  69. youpaiponlineStateV.layer.borderWidth = 2.0f;
  70. youpaiponlineStateV.clipsToBounds = YES;
  71. youpaiponlineStateV.hidden = YES;
  72. [self.contentView addSubview:youpaiponlineStateV];
  73. self.youpaiponlineStateV = youpaiponlineStateV;
  74. [youpaiponlineStateV mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.offset(9.0f);
  76. make.top.equalTo(youpaipavatarImgV.mas_top).offset(-3.0f);
  77. make.size.mas_offset(CGSizeMake(12.0f, 12.0f));
  78. }];
  79. UILabel *youpaipnicknameL = [[UILabel alloc] init];
  80. youpaipnicknameL.textColor = LZ273145Color;
  81. youpaipnicknameL.font = LCFont(14.0f);
  82. [bgV addSubview:youpaipnicknameL];
  83. self.youpaipnicknameL = youpaipnicknameL;
  84. [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
  86. make.top.offset(12.0f);
  87. }];
  88. UIImageView *youpaipimmortalImgV = [[UIImageView alloc] init];
  89. youpaipimmortalImgV.image = [UIImage imageNamed:@"vqu_images_home_immortal"];
  90. youpaipimmortalImgV.hidden = YES;
  91. [bgV addSubview:youpaipimmortalImgV];
  92. self.youpaipimmortalImgV = youpaipimmortalImgV;
  93. [youpaipimmortalImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.offset(0.0f);
  95. make.centerY.equalTo(youpaipnicknameL);
  96. make.size.mas_offset(CGSizeMake(31.0f, 12.0f));
  97. }];
  98. UIImageView *youpaipvipImgV = [[UIImageView alloc] init];
  99. youpaipvipImgV.hidden = YES;
  100. [bgV addSubview:youpaipvipImgV];
  101. self.youpaipvipImgV = youpaipvipImgV;
  102. [youpaipvipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.left.offset(0.0f);
  104. make.centerY.equalTo(youpaipnicknameL);
  105. make.size.mas_offset(CGSizeMake(30.0f, 19.0f));
  106. }];
  107. UIImageView *addressImgV = [[UIImageView alloc] init];
  108. addressImgV.image = [UIImage imageNamed:@"vqu_images_home_city"];
  109. [bgV addSubview:addressImgV];
  110. [addressImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
  112. make.top.equalTo(youpaipnicknameL.mas_bottom).offset(3.0f);
  113. make.size.mas_offset(CGSizeMake(12.0f, 12.0f));
  114. }];
  115. UILabel *youpaipcityL = [[UILabel alloc] init];
  116. youpaipcityL.textColor = LZA3AABEColor;
  117. youpaipcityL.font = LCFont(10.0f);
  118. [bgV addSubview:youpaipcityL];
  119. self.youpaipcityL = youpaipcityL;
  120. [youpaipcityL mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.left.equalTo(addressImgV.mas_right).offset(0.0f);
  122. make.centerY.equalTo(addressImgV);
  123. }];
  124. UIButton *youpaipchatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  125. [youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_accost"] forState:UIControlStateNormal];
  126. [youpaipchatBtn setTitle:@"心动" forState:UIControlStateNormal];
  127. [youpaipchatBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  128. youpaipchatBtn.titleLabel.font = LCFont(8.0f);
  129. [youpaipchatBtn addTarget:self action:@selector(youpaipchatBtnClick) forControlEvents:UIControlEventTouchUpInside];
  130. CGFloat totalHeight = 42.0f;
  131. CGFloat imageSize = 38.0f;
  132. CGFloat titleHeight = 10.0f;
  133. youpaipchatBtn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize), -(imageSize/2.0f), 0.0, - imageSize);
  134. youpaipchatBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize, - (totalHeight - titleHeight), 0);
  135. [bgV addSubview:youpaipchatBtn];
  136. self.youpaipchatBtn = youpaipchatBtn;
  137. [youpaipchatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.right.offset(-5.0f);
  139. make.size.mas_offset(CGSizeMake(38.0f, 42.0f));
  140. make.centerY.equalTo(bgV);
  141. }];
  142. UILabel *youpaipsignL = [[UILabel alloc] init];
  143. youpaipsignL.textColor = LZA3AABEColor;
  144. youpaipsignL.font = LCFont(12.0f);
  145. [bgV addSubview:youpaipsignL];
  146. self.youpaipsignL = youpaipsignL;
  147. [youpaipsignL mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
  149. make.top.equalTo(addressImgV.mas_bottom).offset(8.0f);
  150. make.right.equalTo(youpaipchatBtn.mas_left).offset(-8.0f);
  151. }];
  152. UIButton *youpaipAudioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  153. [youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
  154. [youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
  155. [youpaipAudioBtn addTarget:self action:@selector(youpaipAudioBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  156. [bgV addSubview:youpaipAudioBtn];
  157. self.youpaipAudioBtn = youpaipAudioBtn;
  158. [youpaipAudioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
  160. make.top.equalTo(addressImgV.mas_bottom).offset(8.0f);
  161. make.size.mas_offset(CGSizeMake(62.5f, 18.0f));
  162. }];
  163. UILabel *youpaipAudioL = [[UILabel alloc] init];
  164. youpaipAudioL.font = LCFont(10.0f);
  165. youpaipAudioL.textColor = LZ7C69FEColor;
  166. [youpaipAudioBtn addSubview:youpaipAudioL];
  167. self.youpaipAudioL = youpaipAudioL;
  168. [youpaipAudioL mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.right.offset(-5.0f);
  170. make.centerY.equalTo(youpaipAudioBtn);
  171. }];
  172. UIView *youpaipfeatureBgV = [[UIView alloc] init];
  173. [bgV addSubview:youpaipfeatureBgV];
  174. self.youpaipfeatureBgV = youpaipfeatureBgV;
  175. [youpaipfeatureBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.left.equalTo(youpaipcityL.mas_right).offset(4.0f);
  177. make.height.offset(12.0f);
  178. make.centerY.equalTo(youpaipcityL);
  179. }];
  180. }
  181. - (void)youpaifreloadWithModel:(YOUPAILCHomeListModel *)model{
  182. self.model = model;
  183. [self.youpaipavatarImgV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:model.youpaipcover] urlWithImageScale:60]];
  184. if (model.youpaipis_new_user) {
  185. self.youpaiponlineStateV.hidden = YES;
  186. self.youpaipnewUserImgV.hidden = NO;
  187. }else{
  188. self.youpaiponlineStateV.hidden = NO;
  189. self.youpaipnewUserImgV.hidden = YES;
  190. }
  191. self.youpaiponlineStateV.backgroundColor = kColors(model.youpaipAddnewColor);
  192. self.youpaipnicknameL.text = model.youpaipnickname;
  193. self.youpaipcityL.text = model.youpaipcity;
  194. UIView *frontV = self.youpaipnicknameL;
  195. self.youpaipimmortalImgV.hidden = YES;
  196. if (model.youpaipis_anchor == 1) {
  197. self.youpaipimmortalImgV.hidden = NO;
  198. [self.youpaipimmortalImgV mas_remakeConstraints:^(MASConstraintMaker *make) {
  199. make.left.equalTo(frontV.mas_right).offset(2.0f);
  200. make.centerY.equalTo(self.youpaipnicknameL);
  201. make.size.mas_offset(CGSizeMake(31.0f, 12.0f));
  202. }];
  203. frontV = self.youpaipimmortalImgV;
  204. }
  205. self.youpaipvipImgV.hidden = YES;
  206. if (model.youpaipvip_icon.length != 0) {
  207. self.youpaipvipImgV.hidden = NO;
  208. [self.youpaipvipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipvip_icon]];
  209. [self.youpaipvipImgV mas_remakeConstraints:^(MASConstraintMaker *make) {
  210. make.left.equalTo(frontV.mas_right).offset(2.0f);
  211. make.centerY.equalTo(self.youpaipnicknameL);
  212. make.size.mas_offset(CGSizeMake(30.0f, 19.0f));
  213. }];
  214. frontV = self.youpaipvipImgV;
  215. }
  216. self.youpaipsignL.text = model.youpaipsign;
  217. self.youpaipAudioBtn.hidden = YES;
  218. self.youpaipsignL.hidden = NO;
  219. if (model.youpaipvoice == 1) {
  220. self.youpaipAudioBtn.hidden = NO;
  221. self.youpaipsignL.hidden = YES;
  222. if (model.youpaipisPlay) {
  223. self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(model.youpaipmp3_second - model.youpaipCurrentPlayTime)];
  224. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateNormal];
  225. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateHighlighted];
  226. }else{
  227. self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(model.youpaipmp3_second)];
  228. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
  229. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
  230. }
  231. }
  232. if (model.youpaipis_beckon) { //心动 true 已心动过,false 未心动过
  233. [self.youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_chat"] forState:UIControlStateNormal];
  234. [self.youpaipchatBtn setTitle:@"私信" forState:UIControlStateNormal];
  235. }else{
  236. [self.youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_accost"] forState:UIControlStateNormal];
  237. [self.youpaipchatBtn setTitle:model.youpaipis_beckon_text forState:UIControlStateNormal];
  238. }
  239. // CGFloat totalHeight = 40.0f;
  240. // CGFloat imageSize = 38.0f;
  241. // CGFloat titleHeight = 10.0f;
  242. // self.youpaipchatBtn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize), -(imageSize/2.0f), 0.0, - imageSize);
  243. // self.youpaipchatBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize, - (totalHeight - titleHeight), 0);
  244. NSMutableArray *features = [NSMutableArray array];
  245. if (model.youpaipage != 0) {
  246. [features addObject:[NSString stringWithFormat:@"%@岁", @(model.youpaipage)]];
  247. }
  248. if (model.youpaipheight.length != 0) {
  249. [features addObject:model.youpaipheight];
  250. }
  251. if (model.youpaipoccupation.length != 0) {
  252. [features addObject:model.youpaipoccupation];
  253. }
  254. [self youpaifeditBtnCountWithCount:features.count];
  255. YOUPAILZUserFeatureView *frontFeatureV = nil;
  256. for (NSInteger i = 0; i < self.youpaipfeatureItems.count; i ++) {
  257. YOUPAILZUserFeatureView *v = self.youpaipfeatureItems[i];
  258. [v youpaifreloadWithFeature:features[i]];
  259. [v mas_remakeConstraints:^(MASConstraintMaker *make) {
  260. if (frontFeatureV == nil) {
  261. make.left.offset(0.0f);
  262. }else{
  263. make.left.equalTo(frontFeatureV.mas_right).offset(4.0f);
  264. }
  265. make.top.bottom.offset(0.0f);
  266. if (i == self.youpaipfeatureItems.count - 1) {
  267. make.right.offset(0.0f);
  268. }
  269. }];
  270. frontFeatureV = v;
  271. }
  272. }
  273. - (void)youpaifreloadCurrentPlayTime{
  274. self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(self.model.youpaipmp3_second - self.model.youpaipCurrentPlayTime)];
  275. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateNormal];
  276. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateHighlighted];
  277. }
  278. - (void)youpaifstopPlay{
  279. self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(self.model.youpaipmp3_second)];
  280. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
  281. [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
  282. }
  283. /// 声音展示点击
  284. - (void)youpaipAudioBtnClick:(UIButton *)sender{
  285. sender.selected = !sender.selected;
  286. self.model.youpaipisPlay = sender.selected;
  287. if (sender.selected) {
  288. [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateNormal];
  289. [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateHighlighted];
  290. }else{
  291. [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
  292. [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
  293. }
  294. if (self.youpaipAudioClickBlock != nil) {
  295. self.youpaipAudioClickBlock(self.model,sender.selected);
  296. }
  297. }
  298. /// 搭讪、心动、私信点击
  299. - (void)youpaipchatBtnClick{
  300. // [self.youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_chat"] forState:UIControlStateNormal];
  301. // [self.youpaipchatBtn setTitle:@"私信" forState:UIControlStateNormal];
  302. if (self.youpaipChatClickBlock != nil) {
  303. self.youpaipChatClickBlock(self.model);
  304. }
  305. }
  306. - (void)youpaifeditBtnCountWithCount:(NSInteger)count{
  307. if (count >= self.youpaipfeatureItems.count) {
  308. [self youpaifaddBtnWithCount:count - self.youpaipfeatureItems.count];
  309. }else{
  310. [self youpaifdeleteBtnWithCount:self.youpaipfeatureItems.count - count];
  311. }
  312. }
  313. - (void)youpaifdeleteBtnWithCount:(NSInteger)count{
  314. if (count != 0) {
  315. for (NSInteger i = 0; i < count; i ++) {
  316. YOUPAILZUserFeatureView *v = self.youpaipfeatureItems.lastObject;
  317. [self.youpaipfeatureItems removeLastObject];
  318. [v removeFromSuperview];
  319. }
  320. }
  321. }
  322. - (void)youpaifaddBtnWithCount:(NSInteger)count{
  323. for (NSInteger i = 0; i < count; i ++) {
  324. [self youpaifcreateBtn];
  325. }
  326. }
  327. - (void)youpaifcreateBtn{
  328. YOUPAILZUserFeatureView *v = [[YOUPAILZUserFeatureView alloc] init];
  329. [self.youpaipfeatureBgV addSubview:v];
  330. [self.youpaipfeatureItems addObject:v];
  331. }
  332. - (NSMutableArray<YOUPAILZUserFeatureView *> *)youpaipfeatureItems{
  333. if (_youpaipfeatureItems == nil) {
  334. _youpaipfeatureItems = [NSMutableArray array];
  335. }
  336. return _youpaipfeatureItems;
  337. }
  338. @end