ios - Replace each character of a given string with the typed character when typing in a UITextField -


i have uitextview have initial text of initial price @ $0.00. user set price entering number , when so, each character, starting right, replaced typed number. example:

  • when typing 1, text's changed $0.01
  • then typing 2, $0.12
  • then 3, $1.23
  • then 4, $12.34
  • then backspace, $1.23
  • another backspace, $0.12

could please show me how setup kind of input of uitextfield in swift? thank you!

use uitextfielddelete , implement this:

func textfield(_ textfield: uitextfield, shouldchangecharactersin range: nsrange, replacementstring string: string) -> bool {     let text: nsstring = (textfield.text ?? "") nsstring     let resultstring = text.replacingcharacters(in: range, with: string)      // take result string (user's text input) , format how wish...     let formattedtext = ...      // set newly formatted string text fields's text property...     textfield.text = formattedtext      // return false user's input not applied text field (you're doing on behalf).     return false } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -