| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // MMMessageVerificationVC.m
- // MingMen
- //
- // Created by 肖雨 on 2017/3/11.
- // Copyright © 2017年 肖雨. All rights reserved.
- //
- #import "NewModifyPhoneViewController.h"
- #import "NewRegistCell.h"
- @interface NewModifyPhoneViewController ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSMutableArray *dataArray;
- UITableView *mainTableView;
- UITextField *phoneTextField;
- UITextField *verificationCodeTextField;
- UIButton *verificationCodeButton;
- }
- @end
- @implementation NewModifyPhoneViewController
- -(void)dealloc
- {
- NSLog(@"修改手机号界面销毁");
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self setNavTitle:@"修改手机号"];
- [self dataInitialization];
- [self loadsView];
-
- }
- #pragma mark - 数据初始化
- -(void)dataInitialization
- {
- phoneTextField = nil;
- verificationCodeTextField = nil;
- verificationCodeButton = nil;
- dataArray = NewMutableArrayInit;
-
- for (int i=0; i<2; i++) {
- NSDictionary *dataDic = [NSDictionary dictionary];
-
- switch (i) {
- case 0:
- dataDic = @{@"nameKey":@"手机号",@"imageKey":@"手机号码",@"placeholderKey":@"请输入新的手机号"};
- [dataArray addObject:dataDic];
- break;
- case 1:
- dataDic = @{@"nameKey":@"验证码",@"imageKey":@"短信",@"placeholderKey":@"请输入短信验证码"};
- [dataArray addObject:dataDic];
- break;
- default:
- break;
- }
- }
- }
- #pragma mark - UI初始化
- -(void)loadsView
- {
- [self.view addSubview:mainTableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, ViewStartY, SCREEN_WIDTH, SCREEN_HEIGHT-ViewStartY) backgroundColor:NewWhiteColor style:0 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
-
- UIView *view;
- mainTableView.tableFooterView = view = [NewControlPackage viewInitWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 84) backgroundColor:NewClearColor hidden:NO tag:101 userInteractionEnabled:YES];
-
- UIImageView *lineImge;
- [view addSubview:lineImge = [NewControlPackage imageViewInitWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-15, .6) image:nil highlightedImage:nil backgroundColor:NewCellLineColor tag:102 hidden:NO userInteractionEnabled:YES]];
-
- UIButton *confirm;
- [view addSubview:confirm = [NewControlPackage buttonInitWithTitle:@"确定" Frame:CGRectMake(20, 40, SCREEN_WIDTH-40, 36) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewNavigationColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(14) tag:105 target:self action:@selector(touchConfirm) hidden:NO userInteractionEnabled:YES]];
- ViewRadius(confirm, 8);
-
- }
- #pragma mark - UITableView Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- return dataArray.count;
- }
- - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- static NSString *Cell = @"Cell";
- NewRegistCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[NewRegistCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
-
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
- cell.image.image = NewImageNamed(dataArray[indexPath.row][@"imageKey"]);
- cell.title.text = dataArray[indexPath.row][@"nameKey"];
-
- if (verificationCodeTextField == nil) {
-
- //获取验证码frame
- float vcwidth = 66;
- float vcheight = cell.height-20;
- float vcx = SCREEN_WIDTH-vcwidth-20;
- float vcy = 10;
-
-
- //输入框frame
- float tx = 110;
- float ty = 2;
- float twidth = SCREEN_WIDTH-tx-20;
- float theight = cell.height-2;
-
-
- UITextField *textField;
- [cell.contentView addSubview:textField = [NewControlPackage textFieldInitWithFrame:CGRectMake(tx, ty, twidth, theight) backgroundImage:nil backgroundColor:NewClearColor textColor:NewGrayColor placeholder:dataArray[indexPath.row][@"placeholderKey"] hidden:NO tag:100+(int)indexPath.row font:NewFont(14) textAlignment:NSTextAlignmentLeft clearButtonMode:NO clearsOnBeginEditing:NO adjustsFontSizeToFitWidth:NO secureTextEntry:NO keyboardType:UIKeyboardTypeDefault returnKeyType:UIReturnKeyDefault userInteractionEnabled:YES]];
- [textField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
-
-
- if (indexPath.row==0) {
-
- phoneTextField = textField;
- //phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
-
-
- }else if (indexPath.row==1) {
-
- verificationCodeTextField = textField;
-
- [cell.contentView addSubview:verificationCodeButton = [NewControlPackage buttonInitWithTitle:@"获取验证码" Frame:CGRectMake(vcx, vcy, vcwidth, vcheight) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewLightGrayColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(10) tag:99 target:self action:@selector(touchVerificationCode:) hidden:NO userInteractionEnabled:YES]];
- ViewRadius(verificationCodeButton, 10);
-
- }
- }
-
- return cell;
- }
- #pragma mark - 作字符输入限制
- - (void)textFieldEditingChanged:(UITextField *)textField
- {
- if (textField == phoneTextField) {
- if ([textField.text length]>11) {
- textField.text=[textField.text substringToIndex:11];//手机号码11位
- }
- }else if (textField == verificationCodeTextField) {
- if ([textField.text length]>4) {
- textField.text=[textField.text substringToIndex:4];//验证码4位
- }
- }
- }
- #pragma mark - 获取验证码
- - (void)touchVerificationCode:(UIButton *)sender
- {
- if (![self verification:nil]) {
- return;
- }
- sender.frame = CGRectMake(sender.left, sender.top, 80, sender.height);
- [self verificationCode:60 sender:sender];
- }
- - (void)verificationCode:(NSInteger)code sender:(UIButton *)sender{
- NSString *str=[NSString stringWithFormat:@"%d秒后重新发送",(int)code];
- [sender setTitle:str forState:UIControlStateNormal];
- sender.enabled=NO;
- if (code==0) {
- sender.enabled=YES;
- [sender setTitle:@"获取验证码" forState:UIControlStateNormal];
- sender.frame = CGRectMake(sender.left, sender.top, 66, sender.height);
- return;
- }
- code--;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self verificationCode:code sender:sender];
- });
- }
- #pragma mark - 确定
- - (void)touchConfirm
- {
- if ([self verification:@"已下发短信验证码"]) {
-
- }
- };
- - (BOOL)verification:(NSString *)status
- {
-
- if (phoneTextField.text.length <= 0) {
- [self.view makeToast:@"手机号码输入有误" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
-
- if ([status isEqualToString:@"已下发短信验证码"]) {
- if (verificationCodeTextField.text.length <= 0) {
- [self.view makeToast:@"验证码输入有误" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- }
-
- return YES;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|