. No problem there. But when I press '9' like 11 or 12 times, it'll make something like: "999999...". I don't want these points. I want it like the default keyboard, to go right. I didn't find a solution. Hope for help.
Thanks
PS: I really need this custom keyboard, so please don't say I should use one of the defaults.
Yeah, it's because the label is to small. (I can't make the label bigger). I tried aligment and horizonzal alignment. Nothing of the 2 worked. Thansk for your help.
As Paulson asked above, what do you mean by "these points"?
At anyrate, assuming you mean the ellipsis, there are several issues to consider...
1) when are you seeing the ellipsis? In an NSLog (I seriously doubt this but...), in a UILabel (which is most likely), or elsewhere. Have a look at the adjustsFontSizeToFitWidth property and also lineBreakMode.
1) I see this '...' in the label (Bildschirmfoto 2010-06-16 um 18.23.51.png). I don't want the text to be smaller. Without custom keyboard, it just works fine. Without custom keyboard, the text in the textfield goes to the left.
Either: Take a look at adjustsFontSizeToFitWidth as in (as JDave suggested):
Code:
myLabel.adjustsFontSizeToFitWidth = YES;
which will scale down the font size so all the text can be displayed.
Or: Limit the number of times the label is updated. You say that:
Quote:
Originally Posted by kimor
I don't want the text to be smaller.
So, maybe adjustsFontSizeToFitWidth is not really an option for you. Alternatively, you can try out how many numbers you can fit on the label without the '...' to appear.
Then, create a new instance variable of type NSInteger (I'll call it counter) and set it to 0 in your viewDidLoad. Then, use something like:
Yeah, that makes sense. (Maximal characters are 6). But I want that you can type more than 8 characters without the dots. Try it out: Take a normal textfield. If you reach the end of the textfield, text will slide to left and you can type more. I want it like this. Sorry that I daze you.
Well, you could just use a TextField. Disable user interaction and make it look "plain" (I think there are different styles) and it's pretty much the same as a label.
(As I said, I can't test this right now so it's just speculation...)
Alternatively, you can always use two different variables. One that stores the "real" number and one that displays the number but only up to a certain point. For example, use an NSInteger to store the number and then use an NSString to hold the text that should be displayed. For the NSString, you can always cut off the digits that should not be displayed. The fact that you don't display the numbers doesn't have to mean they aren't there.
Hope this helps.
Cheers,
Bob
__________________ We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.
NSInteger allowedDigits = 6;
NSInteger realNumber = 123456789; // those are 9, three more than allowed
NSString *displayedNumber = [NSString stringWithFormat: @"%i", realNumber];
while (displayedNumber.length > allowedDigits) {
// remove the first digit of displayedNumber (first the 1, then the 2, then the 3)
}
Also, take a look at NSString's class reference. There are a couple of other methods that might allow a more elegant solution.
With this approach, you can use displayedNumber to appear on your screen...
Code:
myLabel.text = displayedNumber;
... while you can use realNumber for your calculations or whatever you do with the number since it holds the "real" number.
Of course you have to update displayedNumber as well as realNumber every time you add or remove a new digit through your custom keyboard.
Also, you might want to make all those variables instance variables so you can use them across your entire class (probably a view controller). Good luck!
Hope this helps.
Cheers,
Bob
__________________ We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.