AccountRechargeOthermoneyTBCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // AccountRechargeOthermoneyTBCell.m
  3. // BuguLive
  4. //
  5. // Created by hym on 2016/10/25.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "AccountRechargeOthermoneyTBCell.h"
  9. static NSString *const ID = @"AccountRechargeOthermoneyTBCell";
  10. @interface AccountRechargeOthermoneyTBCell()<UITextFieldDelegate>
  11. @property (weak, nonatomic) IBOutlet UILabel *otherLabel;
  12. @end
  13. @implementation AccountRechargeOthermoneyTBCell
  14. - (void)awakeFromNib
  15. {
  16. [super awakeFromNib];
  17. self.backgroundColor =[UIColor whiteColor];
  18. self.lbOtherMoney.textColor =kAppGrayColor2;
  19. [self.btnOperation setTintColor:kAppGrayColor1];
  20. self.btnOperation.layer.borderColor = kAppGrayColor1.CGColor;
  21. self.btnOperation.layer.borderWidth = kBorderWidth;
  22. self.btnOperation.layer.cornerRadius = 15;
  23. self.btnOperation.titleLabel.textColor = kAppGrayColor1;
  24. self.otherLabel.textColor =kAppGrayColor1;
  25. self.lbOtherMoney.textAlignment = NSTextAlignmentLeft;
  26. self.tfOtherMoney.delegate = self;
  27. [self.tfOtherMoney addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventEditingChanged];
  28. }
  29. + (instancetype)cellWithTbaleview:(UITableView *)newTableview
  30. {
  31. AccountRechargeOthermoneyTBCell *cell = [newTableview dequeueReusableCellWithIdentifier:ID];
  32. if (!cell)
  33. {
  34. cell = [[[NSBundle mainBundle] loadNibNamed:@"AccountRechargeOthermoneyTBCell" owner:nil options:nil]lastObject];
  35. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  36. }
  37. return cell;
  38. }
  39. #pragma marlk textfieldDelegate代理
  40. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  41. {
  42. if (textField == self.tfOtherMoney)
  43. {
  44. if (![string isNumber])
  45. {
  46. return NO;
  47. }
  48. if (string.length == 0)
  49. return YES;
  50. NSInteger existedLength = textField.text.length;
  51. NSInteger selectedLength = range.length;
  52. NSInteger replaceLength = string.length;
  53. if (existedLength - selectedLength + replaceLength > 6)
  54. {
  55. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"单次兑换超过上限")];
  56. return NO;
  57. }
  58. }
  59. return YES;
  60. }
  61. - (void)valueChanged
  62. {
  63. NSInteger rateCoin = [self.tfOtherMoney.text integerValue];
  64. rateCoin = rateCoin*[self.rate floatValue];
  65. self.lbOtherMoney.text = [NSString stringWithFormat:@"%zd",rateCoin];
  66. }
  67. - (IBAction)onClickOperation:(id)sender
  68. {
  69. if (_tfOtherMoney.text.length == 0)
  70. {
  71. [FanweMessage alert:ASLocalizedString(@"请输入兑换金额")];
  72. return;
  73. }
  74. else if([_tfOtherMoney.text doubleValue] == 0)
  75. {
  76. [FanweMessage alert:ASLocalizedString(@"兑换金额有误")];
  77. return;
  78. }
  79. if (self.block)
  80. {
  81. self.block(self.tfOtherMoney.text);
  82. }
  83. }
  84. @end