// // JXDramaCell.m // AICity // // Created by TogetherWatch on 2025-10-13. // #import "JXDramaCell.h" @implementation JXDramaCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setupUI]; } return self; } - (void)setupUI { self.backgroundColor = [UIColor whiteColor]; self.layer.cornerRadius = 8; self.layer.masksToBounds = YES; // 封面图 self.coverImageView = [[UIImageView alloc] init]; self.coverImageView.contentMode = UIViewContentModeScaleAspectFill; self.coverImageView.clipsToBounds = YES; self.coverImageView.backgroundColor = [UIColor lightGrayColor]; [self.contentView addSubview:self.coverImageView]; // 标题 self.titleLabel = [[UILabel alloc] init]; self.titleLabel.font = [UIFont boldSystemFontOfSize:14]; self.titleLabel.numberOfLines = 2; [self.contentView addSubview:self.titleLabel]; // 评分 self.ratingLabel = [[UILabel alloc] init]; self.ratingLabel.font = [UIFont systemFontOfSize:12]; self.ratingLabel.textColor = [UIColor orangeColor]; [self.contentView addSubview:self.ratingLabel]; // 播放量 self.viewCountLabel = [[UILabel alloc] init]; self.viewCountLabel.font = [UIFont systemFontOfSize:12]; self.viewCountLabel.textColor = [UIColor grayColor]; [self.contentView addSubview:self.viewCountLabel]; // 付费标识 self.paidBadge = [[UIView alloc] init]; self.paidBadge.backgroundColor = [UIColor redColor]; self.paidBadge.layer.cornerRadius = 10; self.paidBadge.hidden = YES; UILabel *paidLabel = [[UILabel alloc] init]; paidLabel.text = @"¥"; paidLabel.textColor = [UIColor whiteColor]; paidLabel.font = [UIFont boldSystemFontOfSize:12]; paidLabel.textAlignment = NSTextAlignmentCenter; [self.paidBadge addSubview:paidLabel]; [self.contentView addSubview:self.paidBadge]; // TODO: 设置Auto Layout约束 // 简化版暂使用固定frame } - (void)layoutSubviews { [super layoutSubviews]; CGFloat width = self.contentView.bounds.size.width; CGFloat height = self.contentView.bounds.size.height; // 简化布局 self.coverImageView.frame = CGRectMake(0, 0, width, height * 0.7); self.titleLabel.frame = CGRectMake(8, height * 0.7 + 4, width - 16, 30); self.ratingLabel.frame = CGRectMake(8, height * 0.7 + 38, 60, 20); self.viewCountLabel.frame = CGRectMake(width - 80, height * 0.7 + 38, 72, 20); self.paidBadge.frame = CGRectMake(width - 30, 8, 20, 20); } - (void)configureWithDrama:(JXDrama *)drama { if (!drama) return; // TODO: 使用SDWebImage或类似库加载封面图 // [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:drama.cover] // placeholderImage:[UIImage imageNamed:@"placeholder"]]; self.titleLabel.text = drama.title; self.ratingLabel.text = [NSString stringWithFormat:@"%.1f", drama.rating]; // 格式化播放量 NSString *viewCountStr; if (drama.viewCount >= 10000) { viewCountStr = [NSString stringWithFormat:@"%.1f万播放", drama.viewCount / 10000.0]; } else if (drama.viewCount >= 1000) { viewCountStr = [NSString stringWithFormat:@"%.1fk播放", drama.viewCount / 1000.0]; } else { viewCountStr = [NSString stringWithFormat:@"%ld播放", (long)drama.viewCount]; } self.viewCountLabel.text = viewCountStr; // 显示付费标识 self.paidBadge.hidden = !drama.isPaid; } @end