JXDramaCell.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // JXDramaCell.m
  3. // AICity
  4. //
  5. // Created by TogetherWatch on 2025-10-13.
  6. //
  7. #import "JXDramaCell.h"
  8. @implementation JXDramaCell
  9. - (instancetype)initWithFrame:(CGRect)frame {
  10. self = [super initWithFrame:frame];
  11. if (self) {
  12. [self setupUI];
  13. }
  14. return self;
  15. }
  16. - (void)setupUI {
  17. self.backgroundColor = [UIColor whiteColor];
  18. self.layer.cornerRadius = 8;
  19. self.layer.masksToBounds = YES;
  20. // 封面图
  21. self.coverImageView = [[UIImageView alloc] init];
  22. self.coverImageView.contentMode = UIViewContentModeScaleAspectFill;
  23. self.coverImageView.clipsToBounds = YES;
  24. self.coverImageView.backgroundColor = [UIColor lightGrayColor];
  25. [self.contentView addSubview:self.coverImageView];
  26. // 标题
  27. self.titleLabel = [[UILabel alloc] init];
  28. self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  29. self.titleLabel.numberOfLines = 2;
  30. [self.contentView addSubview:self.titleLabel];
  31. // 评分
  32. self.ratingLabel = [[UILabel alloc] init];
  33. self.ratingLabel.font = [UIFont systemFontOfSize:12];
  34. self.ratingLabel.textColor = [UIColor orangeColor];
  35. [self.contentView addSubview:self.ratingLabel];
  36. // 播放量
  37. self.viewCountLabel = [[UILabel alloc] init];
  38. self.viewCountLabel.font = [UIFont systemFontOfSize:12];
  39. self.viewCountLabel.textColor = [UIColor grayColor];
  40. [self.contentView addSubview:self.viewCountLabel];
  41. // 付费标识
  42. self.paidBadge = [[UIView alloc] init];
  43. self.paidBadge.backgroundColor = [UIColor redColor];
  44. self.paidBadge.layer.cornerRadius = 10;
  45. self.paidBadge.hidden = YES;
  46. UILabel *paidLabel = [[UILabel alloc] init];
  47. paidLabel.text = @"¥";
  48. paidLabel.textColor = [UIColor whiteColor];
  49. paidLabel.font = [UIFont boldSystemFontOfSize:12];
  50. paidLabel.textAlignment = NSTextAlignmentCenter;
  51. [self.paidBadge addSubview:paidLabel];
  52. [self.contentView addSubview:self.paidBadge];
  53. // TODO: 设置Auto Layout约束
  54. // 简化版暂使用固定frame
  55. }
  56. - (void)layoutSubviews {
  57. [super layoutSubviews];
  58. CGFloat width = self.contentView.bounds.size.width;
  59. CGFloat height = self.contentView.bounds.size.height;
  60. // 简化布局
  61. self.coverImageView.frame = CGRectMake(0, 0, width, height * 0.7);
  62. self.titleLabel.frame = CGRectMake(8, height * 0.7 + 4, width - 16, 30);
  63. self.ratingLabel.frame = CGRectMake(8, height * 0.7 + 38, 60, 20);
  64. self.viewCountLabel.frame = CGRectMake(width - 80, height * 0.7 + 38, 72, 20);
  65. self.paidBadge.frame = CGRectMake(width - 30, 8, 20, 20);
  66. }
  67. - (void)configureWithDrama:(JXDrama *)drama {
  68. if (!drama) return;
  69. // TODO: 使用SDWebImage或类似库加载封面图
  70. // [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:drama.cover]
  71. // placeholderImage:[UIImage imageNamed:@"placeholder"]];
  72. self.titleLabel.text = drama.title;
  73. self.ratingLabel.text = [NSString stringWithFormat:@"%.1f", drama.rating];
  74. // 格式化播放量
  75. NSString *viewCountStr;
  76. if (drama.viewCount >= 10000) {
  77. viewCountStr = [NSString stringWithFormat:@"%.1f万播放", drama.viewCount / 10000.0];
  78. } else if (drama.viewCount >= 1000) {
  79. viewCountStr = [NSString stringWithFormat:@"%.1fk播放", drama.viewCount / 1000.0];
  80. } else {
  81. viewCountStr = [NSString stringWithFormat:@"%ld播放", (long)drama.viewCount];
  82. }
  83. self.viewCountLabel.text = viewCountStr;
  84. // 显示付费标识
  85. self.paidBadge.hidden = !drama.isPaid;
  86. }
  87. @end