0

I am wondering if there is an easy way to do this without using substrings and ranges. Basically I am wanting to accomplish entering a price amount in a UILabel.

Example:

enter image description here

When the user types, I want to input the price, obviously thats needs to go right to left, and once I get to dollars - append on as much as needed. I looked at this answer but didn't get anywhere with it. It's a little tricky because the dollar sign and decimal points are part of the UILabel, and right now I am just setting that text of the UILabel = textfield.text. Any ideas appreciated.

Community
  • 1
  • 1
Jason Renaldo
  • 2,802
  • 3
  • 37
  • 48
  • look into these sources : https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=currency – HelmiB Aug 02 '13 at 01:51
  • one side u r saying u have UILabel and u want to take input in UILabel using keyboard. How key will open on click of UILabel. it is not UITextField – Prince Kumar Sharma Aug 02 '13 at 05:32

2 Answers2

0

That's simple. You can custom the number keyboard.

The method is like this one:

  1. add notification for keyboard slide up

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

Don’t forget to remove the observer from the notification center in the appropriate place once you’re done with the whole thing:

[[NSNotificationCenter defaultCenter] removeObserver:self];

2.All we have to do in the keyboardWillShow method is to locate the keyboard view and add our button to it. The keyboard view is part of a second UIWindow of our application as others have already figured out (see this thread). So we take a reference to that window (it will be the second window in most cases, so objectAtIndex:1 in the code below is fine), traverse its view hierarchy until we find the keyboard and add the button to its lower left:

- (void)keyboardWillShow:(NSNotification *)note {  
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            [keyboard addSubview:doneButton];
    }
}
IronManGill
  • 7,222
  • 2
  • 31
  • 52
timothy lau
  • 386
  • 2
  • 2
0

You can use AttributedString for the showing $ sign on UILabel.