Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, this is a bit late but I figured I would give this a shot anyway. This is probably more of a workaround and may be messy code, but it worked for me. I connected a label and a hidden textfield in IB, and I wrote this code using the UITextFieldDelegate delegate.</p> <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField == fineHiddenTextField) { NSString *fineText = [textField.text stringByReplacingCharactersInRange:range withString:string]; if ([fineText length] == 0) { NSString *emptyFine = @"0.00"; float fineValue = [emptyFine floatValue]; fineEntryLabel.text = [NSString stringWithFormat:@"%.2f", fineValue]; } else if ([fineText length] == 1) { NSString *firstDec = [NSString stringWithFormat:@"0.0%@", fineText]; float fineValue = [firstDec floatValue]; fineEntryLabel.text = [NSString stringWithFormat:@"%.2f", fineValue]; } else if ([fineText length] == 2) { NSString *secondDec = [NSString stringWithFormat:@"0.%@", fineText]; float fineValue = [secondDec floatValue]; fineEntryLabel.text = [NSString stringWithFormat:@"%.2f", fineValue]; } else { int decimalPlace = [fineText length] - 2; NSString *fineDollarAmt = [fineText substringToIndex:decimalPlace]; NSString *fineCentsAmt = [fineText substringFromIndex:decimalPlace]; NSString *finalFineValue = [NSString stringWithFormat:@"%@.%@", fineDollarAmt, fineCentsAmt]; float fineValue = [finalFineValue floatValue]; fineEntryLabel.text = [NSString stringWithFormat:@"%.2f", fineValue]; } //fineEntryLabel.text = [NSString stringWithFormat:@"%.2f", fineValue]; return YES; } } </code></pre> <p>Not exactly the neatest, but it really got the job done. The initial if statement was just to make sure that this was only happening for this one particular textField (As there are multiple throughout the same page.) This code was intended for the input of money (The amount of a fine paid) and I wanted it to be simple and easy to use. Just set your label to align from the right, and it should.</p> <p>I am a little wired on coffee right now, but I will answer any questions you may have. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload