OtherChangeView.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // OtherChangeView.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 17/3/15.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "OtherChangeView.h"
  9. @interface OtherChangeView()<RechargeWayViewDelegate,UITextFieldDelegate>
  10. @end
  11. @implementation OtherChangeView
  12. - (instancetype)initWithFrame:(CGRect)frame andUIViewController:(UIViewController *)viewController
  13. {
  14. if (self = [super initWithFrame:frame])
  15. {
  16. self.backgroundColor = kAppRechargeSelectColor;
  17. self.layer.cornerRadius = 5;
  18. self.layer.masksToBounds = YES;
  19. CGFloat bthOrignx = (self.width/2-80)/2;
  20. _rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  21. _rechargeBtn.titleLabel.font = kAppLargeTextFont;
  22. _rechargeBtn.frame = CGRectMake(bthOrignx, 30, 80, 18);
  23. [_rechargeBtn setTitle:ASLocalizedString(@"充值")forState:UIControlStateNormal];
  24. [_rechargeBtn setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  25. [_rechargeBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  26. [self addSubview:_rechargeBtn];
  27. _lineView = [[UIView alloc] initWithFrame:CGRectMake(self.width/2-0.25, 30, 0.5, 18)];
  28. //_lineView.backgroundColor = [BGUtils colorWithHexString:@"4dffffff"];
  29. _lineView.backgroundColor = kAppSpaceColor;
  30. [self addSubview:_lineView];
  31. _exchangeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  32. _exchangeBtn.titleLabel.font = kAppLargeTextFont;
  33. _exchangeBtn.frame = CGRectMake(self.width/2+bthOrignx, 30, 80, 18);
  34. [_exchangeBtn setTitle:ASLocalizedString(@"兑换")forState:UIControlStateNormal];
  35. //[_exchangeBtn setTitleColor:[BGUtils colorWithHexString:@"4dffffff"] forState:UIControlStateNormal];
  36. [_exchangeBtn setTitleColor:kAppGrayColor3 forState:UIControlStateNormal];
  37. [_exchangeBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  38. [self addSubview:_exchangeBtn];
  39. _selectLineView = [[UIView alloc] initWithFrame:CGRectMake((self.width/2-50)/2, CGRectGetMaxY(_rechargeBtn.frame)+10, 50, 2)];
  40. _selectLineView.backgroundColor = kAppGrayColor1;
  41. [self addSubview:_selectLineView];
  42. if ([GlobalVariables sharedInstance].appModel.open_game_module == 0 || [GlobalVariables sharedInstance].appModel.open_diamond_game_module == 1)
  43. {
  44. _rechargeBtn.frame = CGRectMake(self.width/2-40, 30, 80, 18);
  45. _lineView.hidden = YES;
  46. _exchangeBtn.hidden = YES;
  47. _selectLineView.hidden = YES;
  48. }
  49. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  50. _closeBtn.frame = CGRectMake(self.width-30, 10, 20, 20);
  51. [_closeBtn setImage:[UIImage imageNamed:@"com_close_2"] forState:UIControlStateNormal];
  52. [_closeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  53. [_closeBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  54. [self addSubview:_closeBtn];
  55. _rechargeWayView = [[RechargeWayView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_selectLineView.frame), self.width, 75)];
  56. _rechargeWayView.delegate = self;
  57. [self addSubview:_rechargeWayView];
  58. _separateView = [[UIView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_rechargeWayView.frame), self.width-20, 0.5)];
  59. _separateView.backgroundColor = kAppSpaceColor;
  60. [self addSubview:_separateView];
  61. _rateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_rechargeWayView.frame)+24, self.width-20, 14)];
  62. _rateLabel.font = kAppSmallTextFont;
  63. _rateLabel.textColor = kAppGrayColor3;
  64. _rateLabel.text = ASLocalizedString(@"兑换比例:20");
  65. [self addSubview:_rateLabel];
  66. _textField = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_rateLabel.frame)+15, self.width-30, 25)];
  67. //_textField.borderStyle = UITextBorderStyleRoundedRect;
  68. _textField.placeholder = ASLocalizedString(@"请输入金额");
  69. _textField.keyboardType = UIKeyboardTypeNumberPad;
  70. _textField.delegate = self;
  71. _textField.font = kAppSmallTextFont;
  72. [self addSubview:_textField];
  73. [_textField addTarget:self action:@selector(changeDiamondsLabel) forControlEvents:UIControlEventEditingChanged];
  74. UIView * linView = [[UIView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_textField.frame), self.width-20, 0.5)];
  75. linView.backgroundColor = kAppSpaceColor;
  76. [self addSubview:linView];
  77. _diamondsLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_textField.frame)+15, self.width-20, 15)];
  78. _diamondsLabel.text = [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
  79. _diamondsLabel.textColor = kAppGrayColor3;
  80. _diamondsLabel.font = kAppSmallTextFont;
  81. _diamondsLabel.textAlignment = NSTextAlignmentRight;
  82. [self addSubview:_diamondsLabel];
  83. _separeLineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height-45, self.width, 0.5)];
  84. _separeLineView.backgroundColor = kAppSpaceColor;
  85. [self addSubview:_separeLineView];
  86. // _verticalLineView = [[UIView alloc] initWithFrame:CGRectMake(self.width/2-1, self.height-45, 1, 45)];
  87. // _verticalLineView.backgroundColor = kAppRechargeBtnColor;
  88. // [self addSubview:_verticalLineView];
  89. CGFloat marginX = (self.width-200)/3;
  90. _cancaleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  91. _cancaleBtn.frame = CGRectMake(marginX, self.height-35, 100, 25);
  92. _cancaleBtn.layer.cornerRadius = 12.5;
  93. _cancaleBtn.layer.masksToBounds = YES;
  94. _cancaleBtn.layer.borderWidth = 0.5;
  95. _cancaleBtn.layer.borderColor = kAppGrayColor1.CGColor;
  96. _cancaleBtn.titleLabel.font = kAppSmallTextFont;
  97. [_cancaleBtn setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  98. [_cancaleBtn setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  99. [_cancaleBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  100. [self addSubview:_cancaleBtn];
  101. _makeSureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  102. _makeSureBtn.frame = CGRectMake(CGRectGetMaxX(_cancaleBtn.frame)+marginX, self.height-35, 100, 25);
  103. _makeSureBtn.layer.cornerRadius = 12.5;
  104. _makeSureBtn.layer.masksToBounds = YES;
  105. _makeSureBtn.backgroundColor = kAppGrayColor1;
  106. _makeSureBtn.titleLabel.font = kAppSmallTextFont;
  107. [_makeSureBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  108. [_makeSureBtn setTitle:ASLocalizedString(@"确定")forState:UIControlStateNormal];
  109. [_makeSureBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  110. [self addSubview:_makeSureBtn];
  111. }
  112. return self;
  113. }
  114. //其它支付
  115. - (void)setOtherPayArr:(NSArray *)otherPayArr
  116. {
  117. _otherPayArr = otherPayArr;
  118. NSMutableArray * arr = [NSMutableArray arrayWithArray:otherPayArr];
  119. for (int i=0; i<otherPayArr.count; ++i)
  120. {
  121. PayTypeModel *model = otherPayArr[i];
  122. if ([model.class_name isEqual:@"Iappay"])
  123. {
  124. [arr removeObjectAtIndex:i];
  125. }
  126. }
  127. _rechargeWayView.rechargeWayArr = arr;
  128. _rechargeWayView.selectIndex = _selectIndex;
  129. }
  130. - (void)setModel:(AccountRechargeModel *)model
  131. {
  132. _model = model;
  133. _rateLabel.text = [NSString stringWithFormat:ASLocalizedString(@"兑换比例:%@"),model.rate];
  134. }
  135. - (void)choseRechargeWayWithWayName:(NSString *)wayName
  136. {
  137. for (int i=0; i<self.otherPayArr.count; ++i)
  138. {
  139. PayTypeModel * model = self.otherPayArr[i];
  140. if ([model.class_name isEqual:wayName])
  141. {
  142. _selectIndex = i;
  143. }
  144. }
  145. }
  146. - (void)clickBtn:(UIButton *)button
  147. {
  148. if (button==_makeSureBtn)
  149. {
  150. if (_textField.text.length == 0 || [_textField.text integerValue] == 0)
  151. {
  152. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入有效的兑换金额")];
  153. return;
  154. }
  155. if (_delegate && [_delegate respondsToSelector:@selector(clickOtherRechergeWithView:)])
  156. {
  157. [_delegate clickOtherRechergeWithView:self];
  158. }
  159. }
  160. else if (button == _closeBtn || button == _cancaleBtn)
  161. {
  162. [self disChangeText];
  163. }
  164. else if (button == _exchangeBtn)
  165. {
  166. self.transform = CGAffineTransformIdentity;
  167. [self endEditing:YES];
  168. if (_delegate && [_delegate respondsToSelector:@selector(clickExchangeWithView:)])
  169. {
  170. [_delegate clickExchangeWithView:self];
  171. }
  172. }
  173. }
  174. - (void)changeDiamondsLabel
  175. {
  176. NSInteger rateCoin = [_textField.text integerValue];
  177. rateCoin = rateCoin*[self.model.rate floatValue];
  178. _diamondsLabel.text = [NSString stringWithFormat:@"%zd%@",rateCoin,self.BuguLive.appModel.diamond_name];
  179. }
  180. - (void)disChangeText
  181. {
  182. [self endEditing:YES];
  183. FWWeakify(self)
  184. [UIView animateWithDuration:0.5 animations:^{
  185. FWStrongify(self)
  186. //self.frame =CGRectMake(10,kScreenH, kScreenW-20, 260);
  187. self.transform = CGAffineTransformIdentity;
  188. } completion:^(BOOL finished) {
  189. FWStrongify(self)
  190. self.hidden = YES;
  191. self.textField.text = nil;
  192. self.diamondsLabel.text = [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
  193. }];
  194. }
  195. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  196. {
  197. if (textField == _textField)
  198. {
  199. if (![string isNumber])
  200. {
  201. return NO;
  202. }
  203. if (string.length == 0)
  204. {
  205. return YES;
  206. }
  207. NSInteger existedLength = textField.text.length;
  208. NSInteger selectedLength = range.length;
  209. NSInteger replaceLength = string.length;
  210. if (existedLength - selectedLength + replaceLength > 6)
  211. {
  212. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"单次兑换超过上限")];
  213. return NO;
  214. }
  215. }
  216. return YES;
  217. }
  218. @end