XYMarkingFriendsSkillListTableViewCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. //
  2. // XYMarkingFriendsSkillListTableViewCell.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/12/7.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYMarkingFriendsSkillListTableViewCell.h"
  9. #import "XYSkillUserModel.h"
  10. @interface XYMarkingFriendsSkillListTableViewCell ()
  11. @property (nonatomic, strong) UIView *infoView;
  12. @property (nonatomic, strong) UIImageView *headImageView;
  13. @property (nonatomic, strong) UILabel *userNameLabel;
  14. @property (nonatomic, strong) UILabel *tagNameLabel;
  15. @property (nonatomic, strong) UIImageView *priceMarkImageView;
  16. @property (nonatomic, strong) UILabel *priceLabel;
  17. @property (nonatomic, strong) UIImageView *jiantouImageView;
  18. @property (nonatomic, strong) UIView *contentTextBgView;
  19. @property (nonatomic, strong) UILabel *contentTextLabel;
  20. @property (nonatomic, strong) NSIndexPath *indexPath;
  21. @end
  22. @implementation XYMarkingFriendsSkillListTableViewCell
  23. + (instancetype)cellWithTableView:(UITableView *)tableView {
  24. static NSString *cellId = @"XYMarkingFriendsSkillListTableViewCell";
  25. XYMarkingFriendsSkillListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  26. if (cell==nil) {
  27. cell = [[XYMarkingFriendsSkillListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  28. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  29. }
  30. return cell;
  31. }
  32. - (void)configureModel:(XYSkillUserModel *)model {
  33. self.skillModel = model;
  34. [self.headImageView sd_setImageWithURL:UrlForString(model.userAvatar) placeholderImage:placeholderUserMainBgImage(model.userSex)];
  35. self.userNameLabel.text = model.userName;
  36. if (StringIsEmpty(model.skillIntro)) {
  37. self.tagNameLabel.hidden = YES;
  38. }else {
  39. self.tagNameLabel.hidden = NO;
  40. self.tagNameLabel.text = model.skillTagName;
  41. CGFloat tagWidth = [HandleString autoLabelWith:self.tagNameLabel.text withSize:CGSizeMake(MAXFLOAT, 11) withFont:Font(8) withLines:1].width;
  42. [self.tagNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  43. make.width.equalTo(@(4.0f+tagWidth+4.0f));
  44. }];
  45. }
  46. self.priceLabel.text = [NSString stringWithFormat:@"%@%@", model.orderPrice, model.priceText];
  47. if (StringIsEmpty(model.skillIntro)) {
  48. self.jiantouImageView.hidden = YES;
  49. self.contentTextBgView.hidden = YES;
  50. [self.contentTextBgView mas_updateConstraints:^(MASConstraintMaker *make) {
  51. make.height.equalTo(@0.0f);
  52. }];
  53. }else {
  54. self.jiantouImageView.hidden = NO;
  55. self.contentTextBgView.hidden = NO;
  56. self.contentTextBgView.backgroundColor = [self getTextBgColor];
  57. self.contentTextLabel.text = model.skillIntro;
  58. CGFloat textHeight = [HandleString autoLabelWith:model.skillIntro withSize:CGSizeMake(SCREEN_WIDTH-40.0f-40.0f, MAXFLOAT) withFont:Font(14) withLines:0].height;
  59. [self.contentTextBgView mas_updateConstraints:^(MASConstraintMaker *make) {
  60. make.height.equalTo(@(8.0f+textHeight+8.0f));
  61. }];
  62. }
  63. if (StringIsEmpty(model.voice)) {
  64. self.voicePlayView.hidden = YES;
  65. }else {
  66. self.voicePlayView.hidden = NO;
  67. self.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", [model.duration integerValue]];
  68. }
  69. self.voicePlayView.playing = NO;
  70. }
  71. - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
  72. self.indexPath = indexPath;
  73. }
  74. #pragma mark — Action
  75. - (void)didClickSkillVoiceAction {
  76. if (self.delegate && [self.delegate respondsToSelector:@selector(cell:didClickVoicePlayActionAtIndexPath:)]) {
  77. [self.delegate cell:self didClickVoicePlayActionAtIndexPath:self.indexPath];
  78. }
  79. }
  80. - (UIColor *)getTextBgColor {
  81. NSInteger row = [NSObject yl_randomNumber:0 to:2];
  82. switch (row) {
  83. case 0:
  84. return ColorFromHexString(@"#7E67FF");
  85. break;
  86. case 1:
  87. return ColorFromHexString(@"#74AFFF");
  88. break;
  89. case 2:
  90. return ColorFromHexString(@"#FF7695");
  91. break;
  92. default:
  93. return ColorFromHexString(@"#7E67FF");
  94. break;
  95. }
  96. }
  97. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  98. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  99. [self setupUI];
  100. }
  101. return self;
  102. }
  103. - (void)setupUI {
  104. self.backgroundColor = Color_Clear;
  105. [self.contentView addSubview:self.infoView];
  106. [self.infoView addSubview:self.headImageView];
  107. [self.infoView addSubview:self.userNameLabel];
  108. [self.infoView addSubview:self.tagNameLabel];
  109. [self.infoView addSubview:self.voicePlayView];
  110. [self.infoView addSubview:self.priceMarkImageView];
  111. [self.infoView addSubview:self.priceLabel];
  112. [self.infoView addSubview:self.jiantouImageView];
  113. [self.infoView addSubview:self.contentTextBgView];
  114. [self.contentTextBgView addSubview:self.contentTextLabel];
  115. [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.left.equalTo(self.contentView).offset(16.0f);
  117. make.right.equalTo(self.contentView).offset(-16.0f);
  118. make.top.equalTo(self.contentView).offset(8.0f);
  119. make.bottom.equalTo(self.contentView).offset(-12.0f);
  120. }];
  121. [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.left.top.equalTo(self.infoView).offset(12.0f);
  123. make.width.height.equalTo(@48.0f);
  124. }];
  125. [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.equalTo(self.headImageView.mas_right).offset(8.0f);
  127. make.top.equalTo(self.headImageView);
  128. make.height.equalTo(@17.0f);
  129. }];
  130. [self.tagNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.left.equalTo(self.userNameLabel.mas_right).offset(4.0f);
  132. make.centerY.equalTo(self.userNameLabel);
  133. make.height.equalTo(@14.0f);
  134. make.width.equalTo(@40.0f);
  135. make.right.lessThanOrEqualTo(self.voicePlayView.mas_left).offset(-10.0f);
  136. }];
  137. [self.voicePlayView mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.right.equalTo(self.infoView.mas_right).offset(-12.0f);
  139. make.centerY.equalTo(self.userNameLabel);
  140. make.height.equalTo(@28.0f);
  141. make.width.equalTo(@90.0f);
  142. }];
  143. [self.priceMarkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.left.equalTo(self.headImageView.mas_right).offset(8.0f);
  145. make.top.equalTo(self.userNameLabel.mas_bottom).offset(4.0f);
  146. make.width.height.equalTo(@10.0f);
  147. }];
  148. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.left.equalTo(self.priceMarkImageView.mas_right).offset(2.0f);
  150. make.centerY.equalTo(self.priceMarkImageView);
  151. make.height.equalTo(@14.0f);
  152. make.right.equalTo(self.infoView).offset(-16.0f);
  153. }];
  154. [self.jiantouImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.centerX.equalTo(self.headImageView);
  156. make.top.equalTo(self.headImageView.mas_bottom).offset(20.0f);
  157. make.width.equalTo(@8.0f);
  158. make.height.equalTo(@4.0f);
  159. }];
  160. [self.contentTextBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.left.equalTo(self.infoView).offset(12.0f);
  162. make.right.equalTo(self.infoView).offset(-12.0f);
  163. make.top.equalTo(self.jiantouImageView.mas_bottom);
  164. make.height.equalTo(@0);
  165. }];
  166. [self.contentTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  167. make.edges.equalTo(self.contentTextBgView).insets(UIEdgeInsetsMake(8.0f, 12.0f, 8.0f, 12.0f));
  168. }];
  169. [self.infoView addViewBorder:Color_Clear redian:8];
  170. [self.headImageView addViewBorder:Color_Clear redian:48/2];
  171. [self.contentTextBgView addViewBorder:Color_Clear redian:6.0f];
  172. [self.voicePlayView addViewBorder:Color_Clear redian:8];
  173. [self.tagNameLabel addViewBorder:Color_Clear redian:7];
  174. }
  175. #pragma mark — Getter
  176. - (UIView *)infoView {
  177. if (!_infoView) {
  178. _infoView = [UIView new];
  179. _infoView.backgroundColor = Color_White;
  180. }
  181. return _infoView;
  182. }
  183. - (UIImageView *)headImageView {
  184. if (!_headImageView) {
  185. _headImageView = [UIImageView new];
  186. _headImageView.contentMode = UIViewContentModeScaleAspectFill;
  187. _headImageView.clipsToBounds = YES;
  188. }
  189. return _headImageView;
  190. }
  191. - (UILabel *)userNameLabel {
  192. if (!_userNameLabel) {
  193. _userNameLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(12)];
  194. }
  195. return _userNameLabel;
  196. }
  197. - (UILabel *)tagNameLabel {
  198. if (!_tagNameLabel) {
  199. _tagNameLabel = [UILabel createLabelTextColor:Color_White fount:Font(8)];
  200. _tagNameLabel.textAlignment = NSTextAlignmentCenter;
  201. _tagNameLabel.backgroundColor = ColorFromHexString(@"#48EBB9");
  202. }
  203. return _tagNameLabel;
  204. }
  205. - (XYSkillVoicePlayView *)voicePlayView {
  206. if (!_voicePlayView) {
  207. _voicePlayView = [[XYSkillVoicePlayView alloc] init];
  208. _voicePlayView.playImage = ImageNamed(@"skill_voice_play_small");
  209. _voicePlayView.pauseImage = ImageNamed(@"skill_voice_pause_small");
  210. _voicePlayView.textColor = Color_TextFont;
  211. _voicePlayView.textFont = Font_B(12);
  212. _voicePlayView.playing = NO;
  213. _voicePlayView.leftSpacing = 6.0f;
  214. _voicePlayView.topSpacing = 4.0f;
  215. _voicePlayView.backgroundColor = ColorFromHexStringWithAlpha(@"#FFFFFF", 1.0);
  216. WeakSelf
  217. [_voicePlayView setDidClickSkillVoiceBlock:^{
  218. [weakSelf didClickSkillVoiceAction];
  219. }];
  220. }
  221. return _voicePlayView;
  222. }
  223. - (UIImageView *)priceMarkImageView {
  224. if (!_priceMarkImageView) {
  225. _priceMarkImageView = [UIImageView new];
  226. _priceMarkImageView.image = ImageNamed(@"xy_friend_skill_price");
  227. }
  228. return _priceMarkImageView;
  229. }
  230. - (UILabel *)priceLabel {
  231. if (!_priceLabel) {
  232. _priceLabel = [UILabel createLabelTextColor:Color_Nakaguro fount:Font(10)];
  233. }
  234. return _priceLabel;
  235. }
  236. - (UIImageView *)jiantouImageView {
  237. if (!_jiantouImageView) {
  238. _jiantouImageView = [UIImageView new];
  239. }
  240. return _jiantouImageView;
  241. }
  242. - (UIView *)contentTextBgView {
  243. if (!_contentTextBgView) {
  244. _contentTextBgView = [UIView new];
  245. }
  246. return _contentTextBgView;
  247. }
  248. - (UILabel *)contentTextLabel {
  249. if (!_contentTextLabel) {
  250. _contentTextLabel = [UILabel createLabelTextColor:Color_White fount:Font(14)];
  251. _contentTextLabel.numberOfLines = 0;
  252. }
  253. return _contentTextLabel;
  254. }
  255. - (void)awakeFromNib {
  256. [super awakeFromNib];
  257. // Initialization code
  258. }
  259. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  260. [super setSelected:selected animated:animated];
  261. // Configure the view for the selected state
  262. }
  263. @end