MGLiveWishListCell.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // MGLiveWishListCell.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/12/6.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGLiveWishListCell.h"
  9. @implementation MGLiveWishListCell
  10. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  11. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  12. [self setUpView];
  13. [self resetView];
  14. self.selectionStyle = UITableViewCellSelectionStyleNone;
  15. }
  16. return self;
  17. }
  18. -(void)setUpView{
  19. UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kRealValue(11), 0, kScreenW - kRealValue(11 * 2), kRealValue(185))];
  20. [bgImgView setImage:[UIImage imageNamed:@"live_wish_bgView"]];
  21. self.bgImgView = bgImgView;
  22. [self.contentView addSubview:bgImgView];
  23. UILabel *titleL = [UILabel new];
  24. titleL.text = ASLocalizedString(@"心愿一");
  25. titleL.font = [UIFont systemFontOfSize:14];
  26. titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  27. _titleL = titleL;
  28. UIImageView *iconImgView = [UIImageView new];
  29. [iconImgView setImage:[UIImage imageNamed:@"live_wish_gift_addBGView"]];
  30. _iconImgView = iconImgView;
  31. UILabel *topicL = [UILabel new];
  32. topicL.text = ASLocalizedString(@"奇才火箭");
  33. topicL.font = [UIFont systemFontOfSize:14];
  34. topicL.textColor = [UIColor colorWithHexString:@"#333333"];
  35. _topicL = topicL;
  36. UIView *line = [UIView new];
  37. line.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
  38. _line = line;
  39. UILabel *contributionL = [UILabel new];
  40. contributionL.text = ASLocalizedString(@"贡献榜");
  41. contributionL.textColor = kBlackColor;
  42. contributionL.font = [UIFont systemFontOfSize:14];
  43. _contributionL = contributionL;
  44. UILabel *countL = [UILabel new];
  45. countL.text = @"520/990";
  46. countL.font = [UIFont systemFontOfSize:12];
  47. countL.textAlignment = NSTextAlignmentRight;
  48. countL.textColor = [UIColor colorWithHexString:@"#999999"];
  49. _countL = countL;
  50. [bgImgView addSubview:self.titleL];
  51. [bgImgView addSubview:self.iconImgView];
  52. [bgImgView addSubview:self.titleL];
  53. [bgImgView addSubview:self.progressBgView];
  54. [bgImgView addSubview:countL];
  55. [self.progressBgView addSubview:self.progressTitntView];
  56. [bgImgView addSubview:self.line];
  57. [bgImgView addSubview:self.contributionView];
  58. [bgImgView addSubview:self.contributionL];
  59. }
  60. -(void)resetCellWithWishType:(MGADD_WISH)wishType WithModel:(MGLiveWishModel *)model{
  61. _titleL.text = ASLocalizedString(@"心愿一");
  62. [_iconImgView sd_setImageWithURL:[NSURL URLWithString:model.g_icon] placeholderImage:nil];
  63. _topicL.text = [NSString stringWithFormat:@"%@",model.g_name];
  64. _progressTitntView.width = [model.g_now_num floatValue] / [model.g_num floatValue] * self.progressBgView.width;
  65. if ([model.g_now_num floatValue] > [model.g_num floatValue]) {
  66. _progressTitntView.width = self.progressBgView.width;
  67. }
  68. [_progressTitntView.layer addSublayer:[self gradientLayerWithColor1:[UIColor colorWithHexString:@"#9D64FF"] AtColor2:[UIColor colorWithHexString:@"#F060F6"] view:_progressTitntView]];
  69. _countL.text = [NSString stringWithFormat:@"%@/%@",model.g_now_num,model.g_num];
  70. for (int i = 0; i < 3; i ++) {
  71. MGLiveWishcontributionView *view = [self.contributionView viewWithTag:100 + i];
  72. NSInteger topUserCount = model.top_user.count;
  73. if (i > topUserCount - 1) {
  74. view.hidden = YES;
  75. }
  76. for (int j = 0; j < model.top_user.count; j++) {
  77. MGLiveWishUserModel *userModel = [MGLiveWishUserModel mj_objectWithKeyValues:model.top_user[j]];
  78. [view.headImgView sd_setImageWithURL:[NSURL URLWithString:userModel.head_image]];
  79. view.nickNameL.text = [NSString stringWithFormat:@"%@",userModel.nick_name];
  80. view.numL.text = [NSString stringWithFormat:ASLocalizedString(@"%@个"),userModel.gift_num];
  81. }
  82. }
  83. [self resetView];
  84. }
  85. -(void)resetView{
  86. _titleL.frame = CGRectMake(kRealValue(15), kRealValue(15), kScreenW * 0.4, 20);
  87. _iconImgView.frame = CGRectMake(_titleL.left, _titleL.bottom + kRealValue(21), kRealValue(30), kRealValue(30));
  88. _topicL.frame = CGRectMake(_iconImgView.right + kRealValue(5), _iconImgView.top + kRealValue(5), self.bgImgView.width - _iconImgView.width - kRealValue(10 * 3), kRealValue(20));
  89. _progressBgView.frame = CGRectMake(_topicL.left, _topicL.bottom + kRealValue(2), kRealValue(281), kRealValue(4));
  90. _progressTitntView.frame = CGRectMake(0, 0, _progressBgView.width / 2, _progressBgView.height);
  91. _countL.frame = CGRectMake(0, _progressBgView.bottom + kRealValue(2), kScreenW / 2, kRealValue(18));
  92. _countL.right = _progressBgView.right;
  93. _line.frame = CGRectMake(kRealValue(8), _iconImgView.bottom + kRealValue(31), kScreenW - kRealValue(19 * 2), kRealValue(1));
  94. _contributionL.frame = CGRectMake(kRealValue(12), _line.bottom + kRealValue(22) , kRealValue(50), kRealValue(20));
  95. _contributionView.frame = CGRectMake(_contributionL.right + kRealValue(5), 0, kScreenW - kRealValue(85), kRealValue(45));
  96. _contributionView.centerY = _contributionL.centerY;
  97. }
  98. -(void)clickDelete:(UIButton *)sender{
  99. }
  100. -(UIView *)progressTitntView{
  101. if (!_progressTitntView) {
  102. _progressTitntView = [UIView new];
  103. }
  104. return _progressTitntView;
  105. }
  106. -(UIView *)progressBgView{
  107. if (!_progressBgView) {
  108. _progressBgView = [UIView new];
  109. _progressBgView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  110. }
  111. return _progressBgView;
  112. }
  113. -(UIView *)contributionView{
  114. if (!_contributionView) {
  115. _contributionView = [UIView new];
  116. NSArray *levelImgArr = [NSArray arrayWithObjects:@"live_wish_contributeion_first",@"live_wish_contributeion_second",@"live_wish_contributeion_third", nil];
  117. CGFloat viewWidth = kRealValue(108);
  118. for (int i = 0 ; i < 3 ; i ++) {
  119. MGLiveWishcontributionView *view = [[MGLiveWishcontributionView alloc]initWithFrame:CGRectMake(viewWidth * i, 0, viewWidth, kRealValue(45))];
  120. view.tag = 100 + i;
  121. view.levelImgView.image = [UIImage imageNamed:levelImgArr[i]];
  122. view.nickNameL.text = levelImgArr[i];
  123. [_contributionView addSubview:view];
  124. }
  125. }
  126. return _contributionView;
  127. }
  128. - (CAGradientLayer*)gradientLayerWithColor1:(UIColor*)color1 AtColor2:(UIColor*)color2 view:(UIView *)view
  129. {
  130. CAGradientLayer* layer = [CAGradientLayer new];
  131. layer.colors = @[ (__bridge id)color1.CGColor, (__bridge id)color2.CGColor];
  132. layer.startPoint = CGPointMake(0.5f, -0.5);
  133. layer.endPoint = CGPointMake(0.5, 1);
  134. layer.frame = view.bounds;
  135. return layer;
  136. }
  137. @end
  138. @implementation MGLiveWishcontributionView
  139. - (instancetype)initWithFrame:(CGRect)frame
  140. {
  141. self = [super initWithFrame:frame];
  142. if (self) {
  143. [self setUpView];
  144. }
  145. return self;
  146. }
  147. -(void)setUpView{
  148. UIImageView *imgView = [UIImageView new];
  149. imgView.backgroundColor = kGrayColor;
  150. imgView.frame = CGRectMake(0, 0, kRealValue(28), kRealValue(28));
  151. imgView.centerY = self.bounds.size.height / 2;
  152. imgView.layer.cornerRadius = kRealValue(28 / 2);
  153. imgView.layer.masksToBounds = YES;
  154. _headImgView = imgView;
  155. UIImageView *levelImg = [UIImageView new];
  156. _levelImgView = levelImg;
  157. _levelImgView.frame = CGRectMake(0, 0, kRealValue(10), kRealValue(13));
  158. _levelImgView.top = imgView.bottom - kRealValue(4);
  159. _levelImgView.centerX = imgView.centerX;
  160. UILabel *nickNameL = [UILabel new];
  161. nickNameL.text = ASLocalizedString(@"昵称");
  162. nickNameL.font = [UIFont systemFontOfSize:12];
  163. nickNameL.textColor = kBlackColor;
  164. nickNameL.frame = CGRectMake(imgView.right + kRealValue(2), _headImgView.top + kRealValue(2), kRealValue(65), kRealValue(16));
  165. _nickNameL = nickNameL;
  166. UILabel *numL = [UILabel new];
  167. numL.text = ASLocalizedString(@"200个");
  168. numL.font = [UIFont systemFontOfSize:12];
  169. numL.textColor = [UIColor colorWithHexString:@"#CD49FF"];
  170. numL.frame = CGRectMake(nickNameL.left , _nickNameL.bottom + kRealValue(2) , kRealValue(65), kRealValue(16));
  171. _numL = numL;
  172. [self addSubview:imgView];
  173. [self addSubview:levelImg];
  174. [self addSubview:nickNameL];
  175. [self addSubview:numL];
  176. }
  177. @end