123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // MusicChooseCell.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/6/8.
- //
- #import "MusicChooseCell.h"
- @interface MusicChooseCell ()
- @property (weak, nonatomic) IBOutlet UILabel *songName;
- @property (weak, nonatomic) IBOutlet UILabel *songAuth;
- @property (weak, nonatomic) IBOutlet UIImageView *uploaderLogo;
- @property (weak, nonatomic) IBOutlet UILabel *uploaderName;
- @property (weak, nonatomic) IBOutlet UIImageView *typeImage;
- @property (weak, nonatomic) IBOutlet UIView *tagView;
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @end
- @implementation MusicChooseCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- - (void)configWithMessage:(MusicMessageModel *)songMessage {
- self.songName.text = [NSString returnNoNullStringWithString:songMessage.musicSheetName];
- self.songAuth.text = [NSString returnNoNullStringWithString:songMessage.composer];
- NSArray *tagArray = [songMessage.musicTagNames componentsSeparatedByString:@","];
- NSString *owner = @"";
- if ([NSString isEmptyString:songMessage.addName]) {
- owner = [NSString stringWithFormat:@"游客%.0f",songMessage.userId];
- }
- else {
- owner = songMessage.addName;
- }
- CGFloat maxWidth = [self getTagViewMaxWidth:owner];
- [self configTagViewWithTagArray:tagArray maxWidth:maxWidth];
- NSString *typeImgName = @"";
- if ([songMessage.chargeType isEqualToString:@"VIP"]) {
- typeImgName = @"music_vip";
- }
- else if ([songMessage.chargeType isEqualToString:@"CHARGE"]) {
- typeImgName = @"music_order";
- }
- else {
- typeImgName = @"music_free";
- }
- [self.typeImage setImage:[UIImage imageNamed:typeImgName]];
-
- self.uploaderName.text = [NSString returnNoNullStringWithString:owner];
- [self.uploaderLogo sd_setImageWithURL:[NSURL URLWithString:[songMessage.addUserAvatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- if (songMessage.isChoose) {
- self.bgView.layer.borderColor = THEMECOLOR.CGColor;
- self.bgView.layer.borderWidth = 1.0f;
- }
- else {
- self.bgView.layer.borderColor = [UIColor whiteColor].CGColor;
- self.bgView.layer.borderWidth = 1.0f;
- }
- }
- - (CGFloat)getTagViewMaxWidth:(NSString *)teacherName {
- CGFloat width = [self getStringWidthInLabel:teacherName font:[UIFont systemFontOfSize:12.0f]];
- return kScreenWidth - 45 - 10 - 14 - width - 8;
- }
- - (void)configTagViewWithTagArray:(NSArray *)tagArray maxWidth:(CGFloat)maxWidth {
- [self.tagView removeAllSubViews];
- CGFloat width = maxWidth;
- CGFloat xSpace = 0.0f;
- for (NSInteger i = 0; i < tagArray.count; i++) {
- NSString *tagString = tagArray[i];
- CGFloat labelWidth = [self getStringWidthInLabel:tagString font:[UIFont systemFontOfSize:11.0f]];
- CGFloat viewWidth = labelWidth + 8;
- if (xSpace + viewWidth > width) {
- return;
- }
- CGRect frame = CGRectMake(xSpace, 0, viewWidth, 16.0f);
- [self createTagLabelViewWithName:tagString frame:frame];
- xSpace += (viewWidth + 6);
- }
- }
- - (CGFloat)getStringWidthInLabel:(NSString *)tagString font:(UIFont *)font {
- CGFloat width = [tagString boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 16.0f) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil].size.width+1;
- return width;
- }
- - (void)createTagLabelViewWithName:(NSString *)name frame:(CGRect)frame {
- UIView *bgView = [[UIView alloc] initWithFrame:frame];
- bgView.backgroundColor = HexRGB(0xfff1de);
- bgView.layer.cornerRadius = 4.0f;
- [self.tagView addSubview:bgView];
-
- UILabel *tagLabel = [[UILabel alloc] init];
- tagLabel.text = name;
- tagLabel.textColor = HexRGB(0xff8c00);
- tagLabel.font = [UIFont systemFontOfSize:11.0f];
- tagLabel.textAlignment = NSTextAlignmentCenter;
- [bgView addSubview:tagLabel];
- [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(bgView.mas_left).offset(4);
- make.right.mas_equalTo(bgView.mas_right).offset(-4);
- make.top.bottom.mas_equalTo(bgView);
- }];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|