0

I've a TextField to user put a number value (Float or Double), but in most of cases it number is Integer, but I must show the value in Float format for example: 3.0, 2.5. When the user put a Integer, the value shows like: 2. How I set a way to TextField automatically put in decimal point value? ps. In the options of content type not have a option to number.

enter image description here

This is the wrong way:

enter image description here

Augusto
  • 3,825
  • 9
  • 45
  • 93

1 Answers1

0

There is no inbox solution, you should do it manually with UITextFieldDelegate:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
   //customize your string here
}
biloshkurskyi.ss
  • 1,358
  • 3
  • 15
  • 34
  • What means "inbox solution" ? – Augusto Aug 13 '18 at 13:01
  • 1
    Resolved by Apple, with their open API. For example in storyboard you don't see possible state for quick problem solving. – biloshkurskyi.ss Aug 13 '18 at 13:06
  • You can check a similar problem but with "-" character: https://stackoverflow.com/q/40946134/1278744 – biloshkurskyi.ss Aug 13 '18 at 13:07
  • The documention says: "Asks the delegate if the specified text should be changed. " . But isn't this that I need. At: https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619599-textfield – Augusto Aug 13 '18 at 13:31
  • It's exactly what youu need becouse of there you get old textfield text and new and you can add or remove this additional character. For example if you see that your prev text lenght is 3 and there is one more number is adding you add "." and that number. So as a result you will get line with all numbers and dot. – biloshkurskyi.ss Aug 13 '18 at 13:35
  • This function handler one character for time, this not helps me, I can't know when user put all data – Augusto Aug 13 '18 at 16:18
  • Exactly, you verify entering and removing numbers that allow to customize each future changing. – biloshkurskyi.ss Aug 13 '18 at 16:31
  • Also you should be familiar with: https://stackoverflow.com/questions/7010547/uitextfield-text-change-event – biloshkurskyi.ss Aug 13 '18 at 16:33