#import ns_assume_nonnull_begin
typedef void (^resultblock)(nsstring *str , nsdictionary *dic,bool isok);
@inte***ce stepfield : uiview
- (instancetype)initwithframe:(cgrect)frame;
@property (nonatomic, assign) nsinteger fieldcount;
@property (nonatomic, copy) resultblock resultblock;
@end
@class uitextfieldadddel;
@protocol textfielddelegate - (void)textfielddelete:(uitextfieldadddel *)textfield;
@end
@inte***ce uitextfieldadddel : uitextfield
@property (nonatomic, assign) id deldelegate;
@end
ns_assume_nonnull_end
#import "stepfield.h"
@inte***ce stepfield ()
<
textfielddelegate
>
@property (nonatomic, strong) nsmutabledictionary *dic;
@property (nonatomic, strong) nsmutablearray *textfieldarr;
@property (nonatomic, strong) nsstring *text;
@property (nonatomic, assign) nsinteger fildtextlength;
@end
@implementation stepfield
/*// only override drawrect: if you perform custom drawing.
// an empty implementation adversely affects performance during animation.
- (void)drawrect:(cgrect)rect
*/- (instancetype)initwithframe:(cgrect)frame
return self;
}-(void)setfieldcount:(nsinteger)fieldcount
-(void)initui
_fildtextlength = 1;
self.textfieldarr = [self addmenubutton:_fieldcount];
}-(nsmutablearray *)addmenubutton:(nsinteger)count
uitextfieldadddel *textfield = [[uitextfieldadddel alloc]init];
textfield.borderstyle = uitextborderstyleline;
[textfield addtarget:self action:@selector(valuechange:) forcontrolevents:(uicontroleventeditingchanged)];
textfield.deldelegate = self;
textfield.frame = cgrectmake(space, y, neww, h);
[textfield settextalignment:(nstextalignmentcenter)];
[self addsubview:textfield];
[arrreturn addobject:textfield];
}return arrreturn;
}-(void)valuechange:(uitextfield *)textfield
// 以下標未key 輸入框內容為value 做鍵對儲存
nsstring *key = [nsstring stringwithformat:@"%zd",i];
nsstring *value ;
if (fild.text.length > 0)
else
[self.dic setvalue:value forkey:key];
}// 從字典中取數所有的輸入框內容
nsstring *strall = [nsstring string];
for (nsinteger i = 0; i< self.textfieldarr.count-1; i++)
// 判斷輸入內容 如果當前輸入框內容為空用空格代替 更新對應的字典
nsstring *key = [nsstring stringwithformat:@"%zd",currentindex];
if (textfield.text.length > 0)
[self.dic setobject:textfield.text forkey:key];
}else
self.text = strall;
// 更新當前需要編輯的輸入框
uitextfield *fild;
if ( currentindex + 1 > self.textfieldarr.count -1 )
else
else
}else
else}}
[fild becomefirstresponder];
if (self.resultblock)
}- (void)textfielddelete:(uitextfieldadddel *)textfield
}if (currentindex <= 0)
else
}// 當前輸入框的下標
nsinteger currentindex = 0;
for (nsinteger i = 0; i< self.textfieldarr.count; i++)
// 以下標未key 輸入框內容為value 做鍵對儲存
nsstring *key = [nsstring stringwithformat:@"%zd",i];
nsstring *value ;
if (fild.text.length > 0)
else
[self.dic setvalue:value forkey:key];
}// 從字典中取數所有的輸入框內容
nsstring *strall = [nsstring string];
for (nsinteger i = 0; i< self.textfieldarr.count-1; i++)
// 判斷輸入內容 如果當前輸入框內容為空用空格代替 更新對應的字典
nsstring *key = [nsstring stringwithformat:@"%zd",currentindex];
if (textfield.text.length > 0)
[self.dic setobject:textfield.text forkey:key];
}else
self.text = strall;
if (self.resultblock)
}-(nsmutabledictionary *)dic
return _dic;
}-(nsstring *)text
return _text;
}@end
@implementation uitextfieldadddel
/* // only override drawrect: if you perform custom drawing.
// an empty implementation adversely affects performance during animation.
- (void)drawrect:(cgrect)rect
*/- (void)deletebackward
}@end
// 呼叫
簡訊驗證碼
簡訊驗證碼 圍繞以下兩個方法開展 1 sendcaptcha 獲取驗證碼 2 commitcaptcha 提交驗證碼 方法 1 addtextchangedlistener 文字變化 2 requestfocus 請求焦點 3 string phone etphonenum.gettext tost...
簡訊驗證碼
你的key access key secret 你自己的key 注意 不要更改 region cn hangzhou product name dysmsapi domain dysmsapi.aliyuncs.com acs client acsclient access key id,acces...
IOS自動獲取簡訊驗證碼
img 1.自定義監聽類 簡訊 用於自動填充驗證碼 public class smscontentobserver extends contentobserver override public void onchange boolean selfchange 要讀取的屬性 address and ...