I am making an app with multiple textfields. I would like when the user enters a number in the textfield, to automatically add the percent symbol when editing ends. Right now, the only way i know how to do that is to convert the text value to float, then use NSNumberFormatterPercentStyle and then send back the value. I guess that there should be a simpler and faster way to do that for multiple textfileds. Does anyone know?
Share
You could use the UITextFieldDelegate‘s
textFieldDidEndEditing:method.For example:
Note the double “%” in the
stringWithFormat:method: this is because a single % on its own is a “format specifier” and will not be taken into account and xcode will give you a warning, so you need to protect it with a second %.