How to calculate as soon as you type in uitextfield in iphone?

I have an idea and I want something like this ..

first UITextfield - price for 10,000 second UItextField preset for ex-70

third UIlabel that will show the result for ex- $ 7,000.00

I want this and also as soon as I type 7 the result label should show $ 700.00

+1


a source to share


1 answer


To respond to every key press, implement the UITextFieldDelegate and especially the textField: shouldChangeCharactersInRange: replacementString: method and set it as a delegate for both priceField and percentage field. Something along the lines of:



- (void)updatePrice {
   float price = [priceField.text floatValue];
   float percentage = [percentageField.text floatValue];
   resultLabel.text = [NSString stringWithFormat:@"$ %.2f", 
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   [self updatePrice];
}

      

+3


a source







All Articles