xcode - Format text field as user is typing -


I currently have two separate text fields in my app and I am trying to convert it to just one. Text fields are used for currency input (one pound, dollar, euro etc. and one for pence, centi etc.) and they work fine, but I need to add some functionality which will not be possible That I do not use a single field of text. Also, I think a text field is more user-friendly.

Actually I would like a text field that formats the form in the form of currency for the user in real time, while they are writing. E.g.

1 format £ 1.00 or $ 1.00 or 1.00 € etc ... as 1000 format £ 1,000.00 or $ 1,000.00 or 1 000,00 € etc ... I did

Has done some research and got some objective examples, but I do not understand how to do this in Swift (I have never programmed in Objective-C).

Any help can be greatly appreciated because I find it very disappointing.

You can use this code:

  funk currency String FormNumber (number: double) - & gt; String {form format = NSNumberFormer () formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle formatter.currencyCode = NSLocale.currentLocale (). DisplayNameForKey (NSLocaleCurrencySymbol, value: NSLocaleCurrencyCode) return formatter.stringFromNumber (number)} Current Drive string = currency Stringformnanbr (21010) println ( "currency string: \ (currency string)") // $ 21,010.00 will print  < / Pre> 

It is necessary that for working, extrapolation is a consistent and functional example of this information.

  Import UIKit Class CurrencyTextFieldExample: UIViewController {currencyFormatter = NSNumberFormatter () Overcode Function ViewDidload () {super.viewDidLoad () // Make any additional setup after loading the view, usually Any nib TextField.addText () textField.addTarget (self, action: "Tekstfild Did Change:" For, Kantrolivents: UIControlEvents.EditingChanged) textField.frame = CGRect (x: 0, y: 40, width: 320, height: 40 ) Tekstfildkkeyboardteepe = Uykeyboardteepeknumberpd Tekstfildkbacgrundklor = Uiklorkligtgrekolor () Selfkwukaddsubviev (Tekstfild) Kurrensifaormtrknmberstyle = Nsnmberformtterstylekkurrensisyle Karrensiformterkkurrensikde = Nslokalekkarrentlokle (). DisplayNameForKey (NSLocaleCurrencySymbol, value: NSLocaleCurrencyCode)} override function has Risivmomiri alert () can be manufactured by {Super.didReceiveMemoryWarning () // then dispose of any resources. } TextTextFieldedDeadChange (TextField: UITFIFFED) {var text = textField.text.stringByReplacingOccurrencesOfString (currency formorimismimbubble, string: ""). StringBeerRelipingOurrenceAustustring (printoutCertifiedContributor, withString: "") .Stringby ReplacingExecutionOffustring (CurrencyFormer.) TextField.text = CurrencyFormatter.stringFromNumber (Text as NSString) .doubleValue / 100.0)}}  

I have questions if you have questions.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -