ios - Add whitespace after character in the TextField -
i creating sdk in user needs enter 4 digit pin , there should space after each character , textfield should securetextentry enabled .i writing following code
- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { nsuinteger newlength = [textfield.text length] + [string length] - range.length; nsstring *text = [textfield.text stringbyreplacingcharactersinrange:range withstring: string]; if (text.length < 13) { textfield.text = [nsstring stringwithformat: @"%@ ", text]; return no; } return newlength <= 12; }
but problem adding space between character space shown dot . solution works fine in non sdk code . trying hard find easy solution
thanks in advance
- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { nsuinteger length = [textfield.text length] + [string length] - range.length; if (length < 10) { nsstring *newstring = [textfield.text stringbyreplacingcharactersinrange:range withstring:string]; nsstring *laststring = [nsstring stringwithformat:@"%c",[newstring characteratindex:newstring.length-1]]; if(![laststring isequaltostring:@" "] && ![string isequaltostring:@""]) newstring = [newstring stringbyappendingstring:@" "]; else { nsrange tempr = nsmakerange(range.location-1, 2); newstring = [textfield.text stringbyreplacingcharactersinrange:tempr withstring:@""]; } textfield.text = newstring; } return no;
}
Comments
Post a Comment