MGLiveAddWishCell.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // MGLiveAddWishCell.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/12/5.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGLiveAddWishCell.h"
  9. @implementation MGLiveAddWishCell
  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 *iconImgView = [UIImageView new];
  19. [iconImgView setImage:kDefaultPreloadHeadImg];
  20. _iconImgView = iconImgView;
  21. UILabel *topicL = [UILabel new];
  22. topicL.text = ASLocalizedString(@"添加礼物和数量");
  23. topicL.font = [UIFont systemFontOfSize:14];
  24. topicL.textColor = [UIColor colorWithHexString:@"#333333"];
  25. _topicL = topicL;
  26. UITextField *textField = [UITextField new];
  27. textField.placeholder = ASLocalizedString(@"数量最多输入5个");
  28. textField.font = [UIFont systemFontOfSize:14];
  29. textField.delegate = self;
  30. textField.textAlignment = NSTextAlignmentRight;
  31. _textField = textField;
  32. UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  33. [addBtn setBackgroundImage:[UIImage imageNamed:@"live_wish_gift_border"] forState:UIControlStateNormal];
  34. [addBtn setTitleColor:[UIColor colorWithHexString:@"#CD49FF"] forState:UIControlStateNormal];
  35. [addBtn setTitle:ASLocalizedString(@"添加")forState:UIControlStateNormal];
  36. addBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  37. addBtn.userInteractionEnabled = NO;
  38. // setImage:[UIImage imageNamed:@"live_wish_delete"] forState:UIControlStateNormal];
  39. [addBtn addTarget:self action:@selector(clickAdd:) forControlEvents:UIControlEventTouchUpInside];
  40. _addBtn = addBtn;
  41. _line = [UIView new];
  42. _line.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
  43. [self.contentView addSubview:iconImgView];
  44. [self.contentView addSubview:topicL];
  45. [self.contentView addSubview:textField];
  46. [self.contentView addSubview:self.line];
  47. [self.contentView addSubview:addBtn];
  48. }
  49. -(void)resetView{
  50. _iconImgView.frame = CGRectMake(kRealValue(15), kRealValue(15), kRealValue(24), kRealValue(24));
  51. _topicL.frame = CGRectMake(_iconImgView.left + kRealValue(10),kRealValue(10), kScreenW / 2, kRealValue(20));
  52. if (self.wishType == MGWISHTYPE_ADD) {
  53. _iconImgView.hidden = YES;
  54. _textField.hidden = NO;
  55. _topicL.left = kRealValue(15);
  56. }else{
  57. _iconImgView.hidden = NO;
  58. _textField.hidden = YES;
  59. _topicL.left = _iconImgView.right + kRealValue(10);
  60. }
  61. _contentL.frame = CGRectMake(kScreenW / 2, kRealValue(15), kScreenW / 2, kRealValue(20));
  62. _textField.frame = CGRectMake(kScreenW / 2 - kRealValue(10), 0, kScreenW / 2, kRealValue(20));
  63. _addBtn.frame = CGRectMake(kScreenW - kRealValue(11) - kRealValue(56), kRealValue(25), kRealValue(56), kRealValue(25));
  64. _textField.centerY = _addBtn.centerY = self.contentL.centerY = self.iconImgView.centerY = self.topicL.centerY;
  65. _line.frame = CGRectMake(0, _topicL.bottom + kRealValue(12) , kScreenW, 1);
  66. }
  67. -(void)resetCellWithWishType:(MGADD_WISH)wishType WithModel:(MGLiveWishModel *)model{
  68. _wishType = wishType;
  69. self.model = model;
  70. if (wishType == MGWISHTYPE_ADD) {
  71. self.addBtn.hidden = YES;
  72. }else if (wishType == MGWISHTYPE_ADD_GIFT){
  73. self.addBtn.hidden = NO;
  74. [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:nil];
  75. self.topicL.text = model.name;
  76. }
  77. [self resetView];
  78. }
  79. -(void)clickAdd:(UIButton *)sender{
  80. if (self.delegate && [self.delegate respondsToSelector:@selector(protocolClickLiveAddWishModel:)]) {
  81. [self.delegate protocolClickLiveAddWishModel:self.model];
  82. }
  83. }
  84. -(void)textFieldDidChangeSelection:(UITextField *)textField{
  85. if (self.textFieldBlock) {
  86. self.textFieldBlock(textField.text);
  87. }
  88. }
  89. @end