ios - Formating a single textfield so that it display is different to all the others -
how set currency in text field display localized currency, leading 0. if types in 16.25 pence formated 0.1625£ respectively. using delegation , formating text fields numbers can passed in, field should localized.
- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { // first, create text end in input field if you'll return yes: nsstring *resultstring = [textfield.text stringbyreplacingcharactersinrange:range withstring:string]; // now, validate text , return no if don't it'll contain. // accomplish trying convert number , see if worked. nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init]; [numberformatter setnumberstyle:nsnumberformatterdecimalstyle]; nsnumber* resultingnumber = [numberformatter numberfromstring:resultstring]; //[numberformatter release]; return resultingnumber != nil;
i not want change, formats fields. want textfield1 have relevant format,how go doing this, think lies in viewdidload method , setting text property localized floating point, cant seem work out how it.
you can specify textfield want format in delegate method above.
if (textfield == textfield1) { // something.... } else { // whatever want other text fields }
for floating point formatting, use -
[mytextfield settext:[nsstring stringwithformat:@"%.2f", myfloat]];
Comments
Post a Comment