123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- //
- // XYMarkingFriendsSkillListTableViewCell.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/12/7.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMarkingFriendsSkillListTableViewCell.h"
- #import "XYSkillUserModel.h"
- @interface XYMarkingFriendsSkillListTableViewCell ()
- @property (nonatomic, strong) UIView *infoView;
- @property (nonatomic, strong) UIImageView *headImageView;
- @property (nonatomic, strong) UILabel *userNameLabel;
- @property (nonatomic, strong) UILabel *tagNameLabel;
- @property (nonatomic, strong) UIImageView *priceMarkImageView;
- @property (nonatomic, strong) UILabel *priceLabel;
- @property (nonatomic, strong) UIImageView *jiantouImageView;
- @property (nonatomic, strong) UIView *contentTextBgView;
- @property (nonatomic, strong) UILabel *contentTextLabel;
- @property (nonatomic, strong) NSIndexPath *indexPath;
- @end
- @implementation XYMarkingFriendsSkillListTableViewCell
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *cellId = @"XYMarkingFriendsSkillListTableViewCell";
- XYMarkingFriendsSkillListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if (cell==nil) {
- cell = [[XYMarkingFriendsSkillListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYSkillUserModel *)model {
-
- self.skillModel = model;
-
- [self.headImageView sd_setImageWithURL:UrlForString(model.userAvatar) placeholderImage:placeholderUserMainBgImage(model.userSex)];
- self.userNameLabel.text = model.userName;
- if (StringIsEmpty(model.skillIntro)) {
- self.tagNameLabel.hidden = YES;
- }else {
- self.tagNameLabel.hidden = NO;
- self.tagNameLabel.text = model.skillTagName;
- CGFloat tagWidth = [HandleString autoLabelWith:self.tagNameLabel.text withSize:CGSizeMake(MAXFLOAT, 11) withFont:Font(8) withLines:1].width;
- [self.tagNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(4.0f+tagWidth+4.0f));
- }];
- }
- self.priceLabel.text = [NSString stringWithFormat:@"%@%@", model.orderPrice, model.priceText];
-
- if (StringIsEmpty(model.skillIntro)) {
- self.jiantouImageView.hidden = YES;
- self.contentTextBgView.hidden = YES;
- [self.contentTextBgView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@0.0f);
- }];
- }else {
- self.jiantouImageView.hidden = NO;
- self.contentTextBgView.hidden = NO;
- self.contentTextBgView.backgroundColor = [self getTextBgColor];
- self.contentTextLabel.text = model.skillIntro;
- CGFloat textHeight = [HandleString autoLabelWith:model.skillIntro withSize:CGSizeMake(SCREEN_WIDTH-40.0f-40.0f, MAXFLOAT) withFont:Font(14) withLines:0].height;
- [self.contentTextBgView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@(8.0f+textHeight+8.0f));
- }];
- }
-
- if (StringIsEmpty(model.voice)) {
- self.voicePlayView.hidden = YES;
- }else {
- self.voicePlayView.hidden = NO;
- self.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", [model.duration integerValue]];
- }
- self.voicePlayView.playing = NO;
- }
- - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
- self.indexPath = indexPath;
- }
- #pragma mark — Action
- - (void)didClickSkillVoiceAction {
- if (self.delegate && [self.delegate respondsToSelector:@selector(cell:didClickVoicePlayActionAtIndexPath:)]) {
- [self.delegate cell:self didClickVoicePlayActionAtIndexPath:self.indexPath];
- }
- }
- - (UIColor *)getTextBgColor {
-
- NSInteger row = [NSObject yl_randomNumber:0 to:2];
- switch (row) {
- case 0:
- return ColorFromHexString(@"#7E67FF");
- break;
- case 1:
- return ColorFromHexString(@"#74AFFF");
- break;
- case 2:
- return ColorFromHexString(@"#FF7695");
- break;
- default:
- return ColorFromHexString(@"#7E67FF");
- break;
- }
- }
-
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- self.backgroundColor = Color_Clear;
-
- [self.contentView addSubview:self.infoView];
- [self.infoView addSubview:self.headImageView];
- [self.infoView addSubview:self.userNameLabel];
- [self.infoView addSubview:self.tagNameLabel];
- [self.infoView addSubview:self.voicePlayView];
- [self.infoView addSubview:self.priceMarkImageView];
- [self.infoView addSubview:self.priceLabel];
-
- [self.infoView addSubview:self.jiantouImageView];
- [self.infoView addSubview:self.contentTextBgView];
- [self.contentTextBgView addSubview:self.contentTextLabel];
-
- [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(16.0f);
- make.right.equalTo(self.contentView).offset(-16.0f);
- make.top.equalTo(self.contentView).offset(8.0f);
- make.bottom.equalTo(self.contentView).offset(-12.0f);
- }];
- [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(self.infoView).offset(12.0f);
- make.width.height.equalTo(@48.0f);
- }];
- [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headImageView.mas_right).offset(8.0f);
- make.top.equalTo(self.headImageView);
- make.height.equalTo(@17.0f);
- }];
- [self.tagNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.userNameLabel.mas_right).offset(4.0f);
- make.centerY.equalTo(self.userNameLabel);
- make.height.equalTo(@14.0f);
- make.width.equalTo(@40.0f);
- make.right.lessThanOrEqualTo(self.voicePlayView.mas_left).offset(-10.0f);
- }];
- [self.voicePlayView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.infoView.mas_right).offset(-12.0f);
- make.centerY.equalTo(self.userNameLabel);
- make.height.equalTo(@28.0f);
- make.width.equalTo(@90.0f);
- }];
- [self.priceMarkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headImageView.mas_right).offset(8.0f);
- make.top.equalTo(self.userNameLabel.mas_bottom).offset(4.0f);
- make.width.height.equalTo(@10.0f);
- }];
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.priceMarkImageView.mas_right).offset(2.0f);
- make.centerY.equalTo(self.priceMarkImageView);
- make.height.equalTo(@14.0f);
- make.right.equalTo(self.infoView).offset(-16.0f);
- }];
- [self.jiantouImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.headImageView);
- make.top.equalTo(self.headImageView.mas_bottom).offset(20.0f);
- make.width.equalTo(@8.0f);
- make.height.equalTo(@4.0f);
- }];
- [self.contentTextBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.infoView).offset(12.0f);
- make.right.equalTo(self.infoView).offset(-12.0f);
- make.top.equalTo(self.jiantouImageView.mas_bottom);
- make.height.equalTo(@0);
- }];
- [self.contentTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentTextBgView).insets(UIEdgeInsetsMake(8.0f, 12.0f, 8.0f, 12.0f));
- }];
- [self.infoView addViewBorder:Color_Clear redian:8];
- [self.headImageView addViewBorder:Color_Clear redian:48/2];
- [self.contentTextBgView addViewBorder:Color_Clear redian:6.0f];
- [self.voicePlayView addViewBorder:Color_Clear redian:8];
- [self.tagNameLabel addViewBorder:Color_Clear redian:7];
- }
- #pragma mark — Getter
- - (UIView *)infoView {
- if (!_infoView) {
- _infoView = [UIView new];
- _infoView.backgroundColor = Color_White;
- }
- return _infoView;
- }
- - (UIImageView *)headImageView {
- if (!_headImageView) {
- _headImageView = [UIImageView new];
- _headImageView.contentMode = UIViewContentModeScaleAspectFill;
- _headImageView.clipsToBounds = YES;
- }
- return _headImageView;
- }
- - (UILabel *)userNameLabel {
- if (!_userNameLabel) {
- _userNameLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(12)];
- }
- return _userNameLabel;
- }
- - (UILabel *)tagNameLabel {
- if (!_tagNameLabel) {
- _tagNameLabel = [UILabel createLabelTextColor:Color_White fount:Font(8)];
- _tagNameLabel.textAlignment = NSTextAlignmentCenter;
- _tagNameLabel.backgroundColor = ColorFromHexString(@"#48EBB9");
- }
- return _tagNameLabel;
- }
- - (XYSkillVoicePlayView *)voicePlayView {
- if (!_voicePlayView) {
- _voicePlayView = [[XYSkillVoicePlayView alloc] init];
- _voicePlayView.playImage = ImageNamed(@"skill_voice_play_small");
- _voicePlayView.pauseImage = ImageNamed(@"skill_voice_pause_small");
- _voicePlayView.textColor = Color_TextFont;
- _voicePlayView.textFont = Font_B(12);
- _voicePlayView.playing = NO;
- _voicePlayView.leftSpacing = 6.0f;
- _voicePlayView.topSpacing = 4.0f;
- _voicePlayView.backgroundColor = ColorFromHexStringWithAlpha(@"#FFFFFF", 1.0);
- WeakSelf
- [_voicePlayView setDidClickSkillVoiceBlock:^{
- [weakSelf didClickSkillVoiceAction];
- }];
- }
- return _voicePlayView;
- }
- - (UIImageView *)priceMarkImageView {
- if (!_priceMarkImageView) {
- _priceMarkImageView = [UIImageView new];
- _priceMarkImageView.image = ImageNamed(@"xy_friend_skill_price");
- }
- return _priceMarkImageView;
- }
- - (UILabel *)priceLabel {
- if (!_priceLabel) {
- _priceLabel = [UILabel createLabelTextColor:Color_Nakaguro fount:Font(10)];
- }
- return _priceLabel;
- }
- - (UIImageView *)jiantouImageView {
- if (!_jiantouImageView) {
- _jiantouImageView = [UIImageView new];
- }
- return _jiantouImageView;
- }
- - (UIView *)contentTextBgView {
- if (!_contentTextBgView) {
- _contentTextBgView = [UIView new];
- }
- return _contentTextBgView;
- }
- - (UILabel *)contentTextLabel {
- if (!_contentTextLabel) {
- _contentTextLabel = [UILabel createLabelTextColor:Color_White fount:Font(14)];
- _contentTextLabel.numberOfLines = 0;
- }
- return _contentTextLabel;
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|