MGAlertIncodeView.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // MGAlertIncodeView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/8/24.
  6. // Copyright © 2019年 xfg. All rights reserved.
  7. //
  8. #import "MGAlertIncodeView.h"
  9. @implementation MGAlertIncodeView
  10. - (instancetype)init
  11. {
  12. self = [super init];
  13. if (self) {
  14. [self setUpView];
  15. }
  16. return self;
  17. }
  18. -(void)setUpView{
  19. CGFloat textFieldHeight = kRealValue(48);
  20. self.bgImgView = [UIImageView new];
  21. self.bgImgView.image = [UIImage imageNamed:@"mg_tab_inviteCode_bg"];
  22. self.bgImgView.userInteractionEnabled = YES;
  23. [self addSubview:self.bgImgView];
  24. self.titleImgView = [UILabel new];
  25. // self.titleImgView.image = [UIImage imageNamed:@"mg_tab_inviteCode"];
  26. [self.bgImgView addSubview:self.titleImgView];
  27. self.titleImgView.text = ASLocalizedString(@"请填写邀请码");
  28. self.titleImgView.textColor = kWhiteColor;
  29. self.titleImgView.font = [UIFont boldSystemFontOfSize:16];
  30. self.titleImgView.userInteractionEnabled = YES;
  31. self.textImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mg_tab_inviteCodeTextImage"]];
  32. self.textImgView.userInteractionEnabled = YES;
  33. [self.bgImgView addSubview:self.textImgView];
  34. self.textField = [UITextField new];
  35. self.textField.placeholder = ASLocalizedString(@"请填写邀请码");
  36. // self.textField.backgroundColor = kWhiteColor;
  37. // self.textField.layer.cornerRadius = textFieldHeight / 2;
  38. // self.textField.layer.masksToBounds = YES;
  39. self.textField.keyboardType = UIKeyboardTypeNumberPad;
  40. [self.textImgView addSubview:self.textField];
  41. self.cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  42. [self.cancleBtn setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  43. self.cancleBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  44. [self.cancleBtn setTitleColor:[UIColor colorWithHexString:@"#A885F5"] forState:UIControlStateNormal];
  45. self.cancleBtn.tag = 1000 + 0;
  46. [self.cancleBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  47. [self.bgImgView addSubview:self.cancleBtn];
  48. self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  49. [self.confirmBtn setTitle:ASLocalizedString(@"确定")forState:UIControlStateNormal];
  50. self.confirmBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  51. [self.confirmBtn setTitleColor:[UIColor colorWithHexString:@"#A885F5"] forState:UIControlStateNormal];
  52. self.confirmBtn.tag = 1000 + 1;
  53. [self.confirmBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  54. [self.bgImgView addSubview:self.confirmBtn];
  55. self.bgImgView.frame = CGRectMake(0, 0, kRealValue(291), kRealValue(193));
  56. self.bgImgView.centerX = kScreenW / 2;
  57. self.bgImgView.centerY = kScreenH / 2;
  58. self.titleImgView.frame = CGRectMake(0, kRealValue(39), kRealValue(140), kRealValue(29));
  59. self.textImgView.frame = CGRectMake(0, self.titleImgView.bottom + kRealValue(26), kRealValue(235), textFieldHeight);
  60. self.textField.frame = self.textImgView.bounds;
  61. self.textField.width = self.textImgView.width - kRealValue(30);
  62. // CGRectMake(0, self.titleImgView.bottom + kRealValue(26), kRealValue(230), textFieldHeight);
  63. self.cancleBtn.frame = CGRectMake(0, self.textImgView.bottom, self.bgImgView.width / 2, kRealValue(40));
  64. self.confirmBtn.frame = CGRectMake(0, self.textImgView.bottom, self.bgImgView.width / 2, kRealValue(40));
  65. self.textField.centerX = self.textImgView.width / 2;
  66. self.textImgView.centerX = self.titleImgView.centerX = self.bgImgView.width / 2;
  67. self.cancleBtn.right = self.bgImgView.width / 2;
  68. self.confirmBtn.left = self.bgImgView.width / 2;
  69. }
  70. -(void)btnClick:(UIButton *)sender{
  71. [self.textField resignFirstResponder];
  72. if (sender == self.confirmBtn && self.textField.text.length < 1) {
  73. [FanweMessage alert:ASLocalizedString(@"邀请码不能为空")];
  74. return;
  75. }else if (sender == self.confirmBtn && self.textField.text.length > 1){
  76. [self postCode:self.textField.text];
  77. }
  78. if (self.clickBlock && sender == self.cancleBtn) {
  79. self.clickBlock(sender.tag - 1000);
  80. }
  81. }
  82. -(void)postCode:(NSString *)code
  83. {
  84. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  85. [mDict setObject:@"login" forKey:@"ctl"];
  86. [mDict setObject:@"invitation" forKey:@"act"];
  87. [mDict setObject:code forKey:@"invitation_id"];
  88. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  89. if ([responseJson toInt:@"status"] == 1)
  90. {
  91. self.clickBlock(0);
  92. [FanweMessage alert:ASLocalizedString(@"提交成功")];
  93. }
  94. else
  95. {
  96. [FanweMessage alert:[responseJson valueForKey:@"error"]];
  97. // __block UITextField *tf = nil;
  98. //
  99. // [BGHUDHelper alert:[responseJson valueForKey:@"error"] action:^{
  100. // [LEEAlert alert].config
  101. // .LeeTitle(ASLocalizedString(@"邀请码"))
  102. // .LeeAddTextField(^(UITextField *textField) {
  103. //
  104. // // 这里可以进行自定义的设置
  105. // textField.placeholder = ASLocalizedString(@"请输入邀请码");
  106. //
  107. // textField.textColor = [UIColor darkGrayColor];
  108. //
  109. // tf = textField; //赋值
  110. // })
  111. // .LeeAction(ASLocalizedString(@"确定"), ^{
  112. //
  113. //
  114. // if(tf.text == nil || tf.text.length < 1)
  115. // {
  116. // // [self checkCode];
  117. // [BGHUDHelper alert:ASLocalizedString(@"邀请码不能为空")action:^{
  118. // [self checkCode];
  119. // }];
  120. // // [BGHUDHelper alert:ASLocalizedString(@"邀请码不能为空")];
  121. // return;
  122. // }
  123. //
  124. // [self postCode:tf.text];
  125. // [tf resignFirstResponder];
  126. // })
  127. // // 点击事件的Block如果不需要可以传nil
  128. // .LeeShow();
  129. // }];
  130. }
  131. } FailureBlock:^(NSError *error) {
  132. }];
  133. //
  134. }
  135. @end