Add a prefix to UITextField

后端 未结 4 1424
故里飘歌
故里飘歌 2021-01-22 02:18

I want a \'$\' Sign in the text field which cannot be erased. A user should be able to enter values after it and if he presses backspace it should only erase the value he entere

4条回答
  •  抹茶落季
    2021-01-22 02:25

    As noted in the previous answer Add a prefix to UITextField

    inside the textFieldDidBeginEditing as delegate method i found using the following code to be best and right way to format string we are pre/post fixing currency symbols/codes

            NSNumberFormatter* formatter = [[NSNumberFormatter alloc]init];
            [formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
            [formatter setPaddingPosition:NSNumberFormatterPadAfterPrefix];
            [formatter setCurrencySymbol:symbol];
            [formatter setMaximumFractionDigits:2];
            [formatter setMinimumFractionDigits:2];
            [formatter setUsesGroupingSeparator:YES];
            [formatter setCurrencyGroupingSeparator:@","];
            [formatter setCurrencyDecimalSeparator:@"."];
    

提交回复
热议问题