Take the 2-minute tour ×

I'm working on an iOS app that requires the user to enter numbers into a UITextField using the keyboard type UIKeyboardTypeDecimalPad. However I just realized that there is no support for entering negative numbers, which is a requirement of the application.

Any ideas or thoughts on how I can accomplish this?

share|improve this question
The keyboard doesn't support negative numbers as well as a pocket calculator doesn't, users have to put a - before the number to deal with negatives. –  user971401 Mar 8 '12 at 7:00
Great question. Did you ever get a better answer than "put a - button next to it" ? –  BrianV Feb 15 '13 at 18:43
add comment

3 Answers

up vote -2 down vote accepted

This clearly isn't my best answer.. but i'm unable to delete it since it is accepted.

may this code will help you:

if you want a negative number just use "-"

NSString *fieldString = [NSString stringWithFormat:@"%@",Textfield.text];


        int fieldValue;
        value = [fString intValue];

this will work for decimal numbers

            double fieldValue;
            value = [fString doubleValue];
share|improve this answer
This doesn't solve the problem because a user cannot enter a "-" from a decimal keyboard. It's basically impossible then? –  Hugo Tunius May 22 '13 at 13:02
@Hugo T somewhere i saw a tutorial making an - sign of the empty button in the decimal keyboard. i will look if i can find it somewhere. –  Floris497 May 23 '13 at 14:25
this is the will work with 3.5" screen but needs some modification for the 4" iPhone 5, and the dot has must be changed into "-" (thats simple) good luck. brygruver.squarespace.com/blog/2009/10/1/… –  Floris497 May 23 '13 at 14:34
add comment

I don't believe that something like that is possible right now (since Apple hasn't implemented it yet). The only option would be to design your own keyboard or use a complete ASCII one.

share|improve this answer
add comment

From what I've found apple has yet to implement such a standard keyboard. However it is possible to add UIButtons to any keyboard window. this link should help, or similar tutorial this link should also help

Basically you register a NSNotificationListener to listen for the keyboard coming up. Grab the keyboards frame and add a UIButton to its view. The above link isn't quite what we want but its the right idea.

In appDelegate,


    - (void)keyboardDidShow:(NSNotification *)note
// Get the Very Top Window on the Display. That's where the Keyboard is.
NSInteger topWindow = [[[UIApplication sharedApplication] windows] count] - 1;
UIWindow *keyboard = [[[UIApplication sharedApplication] windows] objectAtIndex:topWindow];
// If the dot has not been created (first time the keyboard has been displayed) create it.
if (self.dot == nil)
    self.dot = [UIButton buttonWithType:UIButtonTypeCustom];
    // Make the dot a subview of the view containing the keyboard.
    [keyboard addSubview:self.dot];
    // Place the dot in the correct location on the keyboard.
    [self.dot setFrame:CGRectMake(0, 427, 106, 53)];
    // Set the overlay graphics. (Use TransDecimalDown.png and TransDecimalUp.png for the Alert Style Keyboard.
    [self.dot setImage:[UIImage imageNamed:@"DecimalUp.png"] forState:UIControlStateNormal];
    [self.dot setImage:[UIImage imageNamed:@"DecimalDown.png"] forState:UIControlStateHighlighted];
    // Give the dot something to do when pressed.
    [self.dot addTarget:self action:@selector(sendDecimal:)  forControlEvents:UIControlEventTouchUpInside];
// Bring the dot to the front of the keyboard.
[keyboard bringSubviewToFront:self.dot];

    - (void)sendDecimal:(id)sender {
// Post a notification that the dot has been pressed. Observing view controllers are then responsible for adding the actual decimal.
[[NSNotificationCenter defaultCenter] postNotificationName:@"DecimalPressed" object:nil];
// Play the Keyboard Click. If the user has these sound effects turned off, the decimal will still click. Sorry.  :(  (Also, doesn't seem to work on the simulator, no keyboard clicks seem to.)

sorry for the horrible code format but you get the idea :)

share|improve this answer
add comment

Your Answer


