MGLiveWishCell.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // MGLiveWishCell.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/12/5.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGLiveWishCell.h"
  9. @implementation MGLiveWishCell
  10. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  11. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  12. [self setUpView];
  13. [self resetView];
  14. }
  15. return self;
  16. }
  17. -(void)setUpView{
  18. UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kRealValue(11), 0, kScreenW - kRealValue(11 * 2), kRealValue(125))];
  19. // bgImgView.userInteractionEnabled = YES;
  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. UILabel *numL = [UILabel new];
  37. numL.text = ASLocalizedString(@"9999个");
  38. numL.font = [UIFont systemFontOfSize:14];
  39. numL.textColor = [UIColor colorWithHexString:@"#CD49FF"];
  40. numL.hidden = YES;
  41. _numL = numL;
  42. UILabel *contenL = [UILabel new];
  43. contenL.text = ASLocalizedString(@"报答方式(选填):编辑8个字以内");
  44. contenL.font = [UIFont systemFontOfSize:14];
  45. contenL.textColor = [UIColor colorWithHexString:@"#666666"];
  46. _contentL = contenL;
  47. UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. [deleteBtn setImage:[UIImage imageNamed:@"live_wish_delete"] forState:UIControlStateNormal];
  49. [deleteBtn addTarget:self action:@selector(clickDelete:) forControlEvents:UIControlEventTouchUpInside];
  50. _deleteBtn = deleteBtn;
  51. [bgImgView addSubview:titleL];
  52. [bgImgView addSubview:numL];
  53. [bgImgView addSubview:iconImgView];
  54. [bgImgView addSubview:topicL];
  55. [bgImgView addSubview:contenL];
  56. [self.contentView addSubview:deleteBtn];
  57. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, bgImgView.bottom, kScreenW, kRealValue(158))];
  58. [view addSubview:self.addWishBtn];
  59. [view addSubview:self.generateBtn];
  60. self.addWishBtn.frame = CGRectMake(0, kRealValue(10), kRealValue(160), kRealValue(47));
  61. self.generateBtn.frame = CGRectMake(0, self.addWishBtn.bottom + kRealValue(15), kRealValue(205), kRealValue(40));
  62. self.generateBtn.centerX = self.addWishBtn.centerX = kScreenW / 2;
  63. _bottomView = view;
  64. _bottomView.hidden = YES;
  65. [self.contentView addSubview:_bottomView];
  66. }
  67. -(void)resetModelArr:(MGLiveWishModel *)model indexPath:(NSInteger)indexPath{
  68. if (!model) {
  69. [self.contentView removeAllSubViews];
  70. [self setUpView];
  71. [self resetView];
  72. return;
  73. }
  74. _model = model;
  75. NSString *title = ASLocalizedString(@"心愿一");
  76. if (indexPath == 0) {
  77. title = ASLocalizedString(@"心愿一");
  78. }else if (indexPath == 1) {
  79. title = ASLocalizedString(@"心愿二");
  80. }else if (indexPath == 2){
  81. title = ASLocalizedString(@"心愿三");
  82. }
  83. _numL.hidden = NO;
  84. _deleteBtn.hidden = NO;
  85. _titleL.text = title;
  86. [_iconImgView sd_setImageWithURL:[NSURL URLWithString:model.g_icon] placeholderImage:nil];
  87. _topicL.text = model.g_name;
  88. _numL.text = [NSString stringWithFormat:ASLocalizedString(@"%@"),model.g_num];
  89. _contentL.text = model.txt;
  90. [self resetView];
  91. }
  92. -(void)resetView{
  93. _titleL.frame = CGRectMake(kRealValue(15), kRealValue(15), kScreenW * 0.4, 20);
  94. _iconImgView.frame = CGRectMake(_titleL.left, _titleL.bottom + kRealValue(10), kRealValue(65), kRealValue(65));
  95. _topicL.frame = CGRectMake(_iconImgView.right + kRealValue(5), _iconImgView.top + kRealValue(10), self.bgImgView.width - _iconImgView.width - kRealValue(10 * 3), kRealValue(20));
  96. [_topicL sizeToFit];
  97. _contentL.frame = CGRectMake(_topicL.left, _topicL.bottom + kRealValue(15), self.bgImgView.width - _iconImgView.width - kRealValue(10 * 3), kRealValue(20));
  98. _numL.frame = CGRectMake(_topicL.right + kRealValue(10), 0, kRealValue(100), kRealValue(20));
  99. _numL.centerY = _topicL.centerY;
  100. _deleteBtn.frame = CGRectMake(self.bgImgView.width - kRealValue(40), kRealValue(25), kRealValue(40), kRealValue(40));
  101. }
  102. -(void)clickDelete:(UIButton *)sender{
  103. if([self.delegate respondsToSelector:@selector(protocolLiveWishClickDelteModel:)])
  104. {
  105. [self.delegate protocolLiveWishClickDelteModel:self.model];
  106. }
  107. }
  108. -(void)clickAddWish:(UIButton *)sender{
  109. if([self.delegate respondsToSelector:@selector(protocolMGLiveWishClickType:)])
  110. {
  111. [self.delegate protocolMGLiveWishClickType:MGWISHTYPE_ADD];
  112. }
  113. }
  114. -(void)generateWish:(UIButton *)sender{
  115. if([self.delegate respondsToSelector:@selector(protocolMGLiveWishClickType:)])
  116. {
  117. [self.delegate protocolMGLiveWishClickType:MGWISHTYPE_GENERATE];
  118. }
  119. }
  120. -(QMUIButton *)addWishBtn{
  121. if (!_addWishBtn) {
  122. _addWishBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  123. [_addWishBtn setTitle:ASLocalizedString(@"添加心愿")forState:UIControlStateNormal];
  124. _addWishBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  125. [_addWishBtn setTitleColor:[UIColor colorWithHexString:@"#CD49FF"] forState:UIControlStateNormal];
  126. _addWishBtn.imagePosition = QMUIButtonImagePositionLeft;
  127. [_addWishBtn setImage:[UIImage imageNamed:@"live_wish_add"] forState:UIControlStateNormal];
  128. _addWishBtn.spacingBetweenImageAndTitle = 2;
  129. [_addWishBtn addTarget:self action:@selector(clickAddWish:) forControlEvents:UIControlEventTouchUpInside];
  130. [_addWishBtn setBackgroundImage:[UIImage imageNamed:@"live_wish_add_border"] forState:UIControlStateNormal];
  131. }
  132. return _addWishBtn;
  133. }
  134. -(UIButton *)generateBtn{
  135. if (!_generateBtn) {
  136. _generateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  137. [_generateBtn setTitle:ASLocalizedString(@"生成心愿")forState:UIControlStateNormal];
  138. [_generateBtn setBackgroundImage:[UIImage imageNamed:@"live_wish_add_generate"] forState:UIControlStateNormal];
  139. [_generateBtn addTarget:self action:@selector(generateWish:) forControlEvents:UIControlEventTouchUpInside];
  140. }
  141. return _generateBtn;
  142. }
  143. @end