Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-16-2010, 10:10 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Unhappy Custom Keyboard

Hi guys,

this is my first post here. I've looked for a solution, but I don't find anything.

This is my problem: I have a custom keyboard, '1 - 9', '.', and special keys. My code is
Code:
-(IBAction)btn9{
	NSString *oldstring = p.text;
	NSString *newstring = [NSString stringWithFormat:@"%@9", oldstring];
	p.text = newstring;
}
. 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.
kimor is offline   Reply With Quote
Old 06-16-2010, 11:00 AM   #2 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Hi,

not sure I understand... do the point (...) appear because the label is too small? What do you try to do? Could you explain in more detail again?

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-16-2010, 11:08 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Default

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.

Should I post a screenshot?
kimor is offline   Reply With Quote
Old 06-16-2010, 11:16 AM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 107
JDave is on a distinguished road
Default

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.

2) You will also likely find this (link to Formatting Numbers – NSNumberFormatter Examples) an interesting read given what you are trying to accomplish.

Good Luck.
JDave is offline   Reply With Quote
Old 06-16-2010, 11:25 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Default

Hi,

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.

2) I don't need number formatting.
kimor is offline   Reply With Quote
Old 06-16-2010, 11:47 AM   #6 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Hi kimor,

you have two options.

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:

Code:
-(IBAction)btn9{
	if (counter <= maxNumbersOfNumbers) {
		NSString *oldstring = p.text;
		NSString *newstring = [NSString stringWithFormat:@"%@9", oldstring];
		p.text = newstring;
		counter++;
	}
}
You also need make sure that you counter--; if you delete a number from the label.

Hope this makes sense.

Cheers,
Bob


EDIT: Maybe you can also use something like p.text.length instead of a "counter" variable. I'm sure you'll find a solution.
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-16-2010, 11:58 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Default

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.

Cheers,
Kimor
kimor is offline   Reply With Quote
Old 06-16-2010, 12:03 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Default

I've made a little graphic, to show you what i mean: Bildschirmfoto 2010-06-16 um 19.02.55.png
kimor is offline   Reply With Quote
Old 06-16-2010, 12:51 PM   #9 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

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.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-16-2010, 12:59 PM   #10 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Default

Sounds great! Could you please do a example?That would be more than great!

Thanks for all you've done. You rock
kimor is offline   Reply With Quote
Old 06-16-2010, 01:10 PM   #11 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

What kind of example?

Random guess:

Code:
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)
}
Take a look at this: Remove leading character from an NSString.

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.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-16-2010, 02:30 PM   #12 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 24
kimor is on a distinguished road
Default

Thanks, but I don't understand it. I think the problems are the NSStrings. Can you avoid them?
kimor is offline   Reply With Quote
Old 06-16-2010, 02:39 PM   #13 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Well, if you want to display the number in a label, you cannot avoid an NSString because the label's text property only accepts NSString's.

Which part of it don't you understand? Maybe I can explain in more detail but only if you ask more specific questions.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Reply

Bookmarks

Tags
custom, keyboard, special

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 322
8 members and 314 guests
Absentia, Domele, fiftysixty, givensur, heshiming, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0